Handle UTF-8 byte order marks in Greasemonkey scripts
See e.g. https://github.com/jerone/UserScripts/issues/135
This commit is contained in:
parent
d0d73eec04
commit
f9327731b8
@ -59,6 +59,7 @@ Fixed
|
|||||||
~~~~~
|
~~~~~
|
||||||
|
|
||||||
- Error when passing a substring with spaces to `:tab-take`.
|
- Error when passing a substring with spaces to `:tab-take`.
|
||||||
|
- Greasemonkey scripts which start with an UTF-8 BOM are now handled correctly.
|
||||||
|
|
||||||
Removed
|
Removed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -234,7 +234,7 @@ class GreasemonkeyManager(QObject):
|
|||||||
if not os.path.isfile(script_filename):
|
if not os.path.isfile(script_filename):
|
||||||
continue
|
continue
|
||||||
script_path = os.path.join(scripts_dir, script_filename)
|
script_path = os.path.join(scripts_dir, script_filename)
|
||||||
with open(script_path, encoding='utf-8') as script_file:
|
with open(script_path, encoding='utf-8-sig') as script_file:
|
||||||
script = GreasemonkeyScript.parse(script_file.read())
|
script = GreasemonkeyScript.parse(script_file.read())
|
||||||
if not script.name:
|
if not script.name:
|
||||||
script.name = script_filename
|
script.name = script_filename
|
||||||
|
@ -130,6 +130,26 @@ def test_load_emits_signal(qtbot):
|
|||||||
gm_manager.load_scripts()
|
gm_manager.load_scripts()
|
||||||
|
|
||||||
|
|
||||||
|
def test_utf8_bom():
|
||||||
|
"""Make sure UTF-8 BOMs are stripped from scripts.
|
||||||
|
|
||||||
|
If we don't strip them, we'll have a BOM in the middle of the file, causing
|
||||||
|
QtWebEngine to not catch the "// ==UserScript==" line.
|
||||||
|
"""
|
||||||
|
script = textwrap.dedent("""
|
||||||
|
\N{BYTE ORDER MARK}// ==UserScript==
|
||||||
|
// @name qutebrowser test userscript
|
||||||
|
// ==/UserScript==
|
||||||
|
""".lstrip('\n'))
|
||||||
|
_save_script(script, 'bom.user.js')
|
||||||
|
gm_manager = greasemonkey.GreasemonkeyManager()
|
||||||
|
|
||||||
|
scripts = gm_manager.all_scripts()
|
||||||
|
assert len(scripts) == 1
|
||||||
|
script = scripts[0]
|
||||||
|
assert '// ==UserScript==' in script.code().splitlines()
|
||||||
|
|
||||||
|
|
||||||
def test_required_scripts_are_included(download_stub, tmpdir):
|
def test_required_scripts_are_included(download_stub, tmpdir):
|
||||||
test_require_script = textwrap.dedent("""
|
test_require_script = textwrap.dedent("""
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
|
Loading…
Reference in New Issue
Block a user