fix(search): allow searching for a literal \c or \r
A query that starts with one of the two modifier prefixes could not be escaped, so the text itself was unreachable: \c and \r were always consumed as modifiers and the query ended up empty. A doubled backslash now ends the modifier section and stands for the literal backslash, and the help line and the docs document it. Fixes #48
This commit is contained in:
5 files changed
+37
-6
No files matched your search
@@ -46,6 +46,25 @@ class TestScrollbackSearch(BaseTest):
|
||||
with self.assertRaises(InvalidQuery):
|
||||
compile_query(parse_query('\\r ('))
|
||||
|
||||
def test_parse_query_escaped_backslash(self):
|
||||
# A doubled backslash searches text starting with a backslash instead of
|
||||
# being read as a modifier, so both modifier prefixes remain reachable.
|
||||
for raw, expected in (('\\\\c', '\\c'), ('\\\\r', '\\r'), ('\\\\C', '\\C'), ('\\\\', '\\')):
|
||||
with self.subTest(raw=raw):
|
||||
q = parse_query(raw)
|
||||
self.ae((q.text, q.case_sensitive, q.is_regex), (expected, False, False))
|
||||
|
||||
# Modifiers still combine with an escaped prefix in the searched text
|
||||
q = parse_query('\\c\\\\r')
|
||||
self.ae((q.text, q.case_sensitive, q.is_regex), ('\\r', True, False))
|
||||
|
||||
# The escaped prefix is matched like any other text, case insensitively
|
||||
# by default, and the case sensitive modifier still applies to it.
|
||||
matches = find_matches(['a \\c b', 'a \\C b'], parse_query('\\\\c'))
|
||||
self.ae([(m.line, m.start, m.end) for m in matches], [(0, 2, 4), (1, 2, 4)])
|
||||
matches = find_matches(['a \\c b', 'a \\C b'], parse_query('\\c\\\\c'))
|
||||
self.ae([(m.line, m.start, m.end) for m in matches], [(0, 2, 4)])
|
||||
|
||||
def test_find_matches_plain(self):
|
||||
lines = ['needle at start', 'Needle again', 'nothing', 'a needle here']
|
||||
matches = find_matches(lines, parse_query('needle'))
|
||||
|
||||
Reference in new issue
Block a user