test for index error on project map replacement regex groups

This commit is contained in:
Alan Hamlett 2016-08-31 14:49:01 +02:00
parent c4d6bb38a1
commit 8ef87d0393
2 changed files with 41 additions and 13 deletions

View file

@ -44,20 +44,23 @@ class ProjectMap(BaseProject):
def _find_project(self, path):
path = os.path.realpath(path)
try:
for pattern, new_proj_name in self._configs.items():
try:
compiled = re.compile(pattern, re.IGNORECASE)
match = compiled.search(path)
if match:
for pattern, new_proj_name in self._configs.items():
try:
compiled = re.compile(pattern, re.IGNORECASE)
match = compiled.search(path)
if match:
try:
return new_proj_name.format(*match.groups())
except re.error as ex:
log.warning(u('Regex error ({msg}) for projectmap pattern: {pattern}').format(
msg=u(ex),
pattern=u(pattern),
))
except TypeError:
pass
except IndexError as ex:
log.warning(u('Regex error ({msg}) for projectmap pattern: {pattern}').format(
msg=u(ex),
pattern=u(new_proj_name),
))
except re.error as ex:
log.warning(u('Regex error ({msg}) for projectmap pattern: {pattern}').format(
msg=u(ex),
pattern=u(pattern),
))
return None