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 <a href="...">.

Escaping quotes means we end up with a literal &#x27; 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.
This commit is contained in:
Ryan Roden-Corrent 2018-09-15 13:35:32 -04:00
parent 28c8e5682a
commit 4f99af5876
No known key found for this signature in database
GPG Key ID: 4E5072F68872BC04
2 changed files with 7 additions and 3 deletions

View File

@ -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'<span class="highlight">\g<0></span>'
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:

View File

@ -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>', '&lt;{foo}&gt;'),
('<a>', "<a>bc", '{&lt;a&gt;}bc'),
('foo', "'foo'", "&#x27;{foo}&#x27;"),
# 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):