From 4f6e085be8000fba74abd209a9445adb557c49cc Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 15 Sep 2017 20:28:04 +0200 Subject: [PATCH] Quote a completed value if it contains " --- qutebrowser/completion/completer.py | 2 +- tests/unit/completion/test_completer.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index 83e4e6fc2..c6a2643fb 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -111,7 +111,7 @@ class Completer(QObject): """ if not s: return "''" - elif any(c in s for c in ' \'\t\n\\'): + elif any(c in s for c in ' "\'\t\n\\'): # use single quotes, and put single quotes into double quotes # the string $'b is then quoted as '$'"'"'b' return "'" + s.replace("'", "'\"'\"'") + "'" diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py index e8667ec22..8914a956b 100644 --- a/tests/unit/completion/test_completer.py +++ b/tests/unit/completion/test_completer.py @@ -240,6 +240,10 @@ def test_update_completion(txt, kind, pattern, pos_args, status_command_stub, ":set fonts hints '12px Hack'|"), (":set fonts hints 'Comic| Sans'", '12px Hack', ":set fonts hints '12px Hack'|"), + # Make sure " is quoted properly + (':set url.start_pages \'["https://www.|example.com"]\'', + '["https://www.example.org"]', + ':set url.start_pages \'["https://www.example.org"]\'|'), # open has maxsplit=0, so treat the last two tokens as one and don't quote (':open foo bar|', 'baz', ':open baz|'), (':open foo| bar', 'baz', ':open baz|'),