diff --git a/qutebrowser/utils/javascript.py b/qutebrowser/utils/javascript.py index 19e6b22c2..731af3ed6 100644 --- a/qutebrowser/utils/javascript.py +++ b/qutebrowser/utils/javascript.py @@ -54,7 +54,7 @@ def _convert_js_arg(arg): if arg is None: return 'undefined' elif isinstance(arg, str): - return string_escape(arg) + return '"{}"'.format(string_escape(arg)) elif isinstance(arg, int): return str(arg) else: diff --git a/tests/unit/utils/test_javascript.py b/tests/unit/utils/test_javascript.py index 3cf649f6d..c2af199a1 100644 --- a/tests/unit/utils/test_javascript.py +++ b/tests/unit/utils/test_javascript.py @@ -123,8 +123,8 @@ class TestStringEscape: @pytest.mark.parametrize('arg, expected', [ - ('foobar', 'foobar'), - ('foo\\bar', r'foo\\bar'), + ('foobar', '"foobar"'), + ('foo\\bar', r'"foo\\bar"'), (42, '42'), (None, 'undefined'), (object(), TypeError),