From 4f99af5876a35ec23e91a2f94a7d44cd81269138 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sat, 15 Sep 2018 13:35:32 -0400 Subject: [PATCH] Don't escape quotes in completion text. Resolves the example case in #4199, but not the larger problem. We don't need to escape quotes as we don't put the string in an attribute value. From the docs at https://docs.python.org/3/library/html.html#html.escape: > If the optional flag quote is true, the characters (") and (') are also > translated; this helps for inclusion in an HTML attribute value > delimited by quotes, as in . Escaping quotes means we end up with a literal ' in the completion view wherever there is a quote in the source text. However, problem in #4199, where unexpected parts of the text are highlighted, can also happen with '<', '>', and '&', which still must be escaped. --- qutebrowser/completion/completiondelegate.py | 5 +++-- tests/unit/completion/test_completiondelegate.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index 779906a83..076b99bed 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -203,8 +203,9 @@ class CompletionItemDelegate(QStyledItemDelegate): columns_to_filter = index.model().columns_to_filter(index) if index.column() in columns_to_filter and pattern: repl = r'\g<0>' - pat = html.escape(re.escape(pattern)).replace(r'\ ', r'|') - txt = html.escape(self._opt.text) + pat = html.escape(re.escape(pattern), quote=False).replace( + r'\ ', r'|') + txt = html.escape(self._opt.text, quote=False) text = re.sub(pat, repl, txt, flags=re.IGNORECASE) self._doc.setHtml(text) else: diff --git a/tests/unit/completion/test_completiondelegate.py b/tests/unit/completion/test_completiondelegate.py index b90c096a2..9d22002ee 100644 --- a/tests/unit/completion/test_completiondelegate.py +++ b/tests/unit/completion/test_completiondelegate.py @@ -86,7 +86,10 @@ def delegate(mock_style_option, mock_text_document, config_stub, mocker, view): ('a b', 'cadb', 'c{a}d{b}'), ('foo', '', '<{foo}>'), ('', "bc", '{<a>}bc'), - ('foo', "'foo'", "'{foo}'"), + + # https://github.com/qutebrowser/qutebrowser/issues/4199 + ('foo', "'foo'", "'{foo}'"), + ('x', "'x'", "'{x}'"), ]) def test_paint(delegate, painter, view, mock_style_option, mock_text_document, pat, txt_in, txt_out):