Bug 1575375 - Fix mozpath.match with python 3.7. r=nalexander

Python 3.7 changed what it escapes with re.escape. Adapt mozpath.match
to account for this.

Differential Revision: https://phabricator.services.mozilla.com/D42750
This commit is contained in:
Mike Hommey committed 2019-08-21 03:12:36 +00:00
1 parent 05d7cd9810
commit 4290b6b425
1 file changed
+9 -2
+9 -2
View File
@@ -93,6 +93,13 @@ def basedir(path, bases):
re_cache = {}
# Python versions < 3.7 return r'\/' for re.escape('/').
if re.escape('/') == '/':
MATCH_STAR_STAR_RE = re.compile(r'(^|/)\\\*\\\*/')
MATCH_STAR_STAR_END_RE = re.compile(r'(^|/)\\\*\\\*$')
else:
MATCH_STAR_STAR_RE = re.compile(r'(^|\\\/)\\\*\\\*\\\/')
MATCH_STAR_STAR_END_RE = re.compile(r'(^|\\\/)\\\*\\\*$')
def match(path, pattern):
@@ -121,8 +128,8 @@ def match(path, pattern):
return True
if pattern not in re_cache:
p = re.escape(pattern)
p = re.sub(r'(^|\\\/)\\\*\\\*\\\/', r'\1(?:.+/)?', p)
p = re.sub(r'(^|\\\/)\\\*\\\*$', r'(?:\1.+)?', p)
p = MATCH_STAR_STAR_RE.sub(r'\1(?:.+/)?', p)
p = MATCH_STAR_STAR_END_RE.sub(r'(?:\1.+)?', p)
p = p.replace(r'\*', '[^/]*') + '(?:/.*)?$'
re_cache[pattern] = re.compile(p)
return re_cache[pattern].match(path) is not None