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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2019-08-21 03:12:36 +00:00
Родитель 388ef77faf
Коммит ade6505592
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -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