Merge pull request #1213 from pypeclub/bugfix/3.0_profile_regex_fix

Fix regex checks in profiles filtering
This commit is contained in:
Milan Kolar 2021-03-31 09:36:38 +02:00 committed by GitHub
commit e8fe8f25a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,6 +59,14 @@ def _profile_exclusion(matching_profiles, logger):
return matching_profiles[0][0]
def fullmatch(regex, string, flags=0):
"""Emulate python-3.4 re.fullmatch()."""
matched = re.match(regex, string, flags=flags)
if matched and matched.span()[1] == len(string):
return matched
return None
def validate_value_by_regexes(value, in_list):
"""Validates in any regex from list match entered value.
@ -87,7 +95,11 @@ def validate_value_by_regexes(value, in_list):
regexes = compile_list_of_regexes(in_list)
for regex in regexes:
if re.match(regex, value):
if hasattr(regex, "fullmatch"):
result = regex.fullmatch(value)
else:
result = fullmatch(regex, value)
if result:
return 1
return -1