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 ' 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:
parent
28c8e5682a
commit
4f99af5876
@ -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:
|
||||
|
@ -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>', '<{foo}>'),
|
||||
('<a>', "<a>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):
|
||||
|
Loading…
Reference in New Issue
Block a user