From 95472620c7a313b06a5e76a782f3f4c5172c483b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 23 Jun 2014 19:28:49 +0200 Subject: [PATCH] Escape backslashes in regexps (match_anywhere/match_consecutive) Fixes https://github.com/joelthelion/autojump/issues/281 --- bin/autojump | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/autojump b/bin/autojump index b1d134b..e087cc8 100755 --- a/bin/autojump +++ b/bin/autojump @@ -241,7 +241,7 @@ def match_anywhere(needles, haystack, ignore_case=False): (path="/moo/foo/baz", weight=10), (path="/foo/baz", weight=10)] """ - regex_needle = '.*' + '.*'.join(needles) + '.*' + regex_needle = '.*' + '.*'.join(needles).replace('\\', '\\\\') + '.*' regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE found = lambda haystack: re.search( regex_needle, @@ -285,7 +285,7 @@ def match_consecutive(needles, haystack, ignore_case=False): regex_no_sep_end = regex_no_sep + '$' regex_one_sep = regex_no_sep + sep + regex_no_sep # can't use compiled regex because of flags - regex_needle = regex_one_sep.join(needles) + regex_no_sep_end + regex_needle = regex_one_sep.join(needles).replace('\\', '\\\\') + regex_no_sep_end regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE found = lambda entry: re.search( regex_needle,