From 65168b4b98dd01646075ff3edc6e22c3a29646d2 Mon Sep 17 00:00:00 2001 From: "sentry-autofix[bot]" <157164994+sentry-autofix[bot]@users.noreply.github.com> Date: Fri, 18 Apr 2025 21:11:06 +0000 Subject: [PATCH] fix: convert glob patterns to regex for matching --- helpers/match.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/helpers/match.py b/helpers/match.py index 4d94c59a2..ebb9a625e 100644 --- a/helpers/match.py +++ b/helpers/match.py @@ -2,6 +2,12 @@ from typing import List, Optional +def _convert_glob_to_regex(pattern: str) -> str: + if pattern == "*": + return ".*" + return pattern + + def match(patterns: Optional[List[str]], string: str) -> bool: if patterns is None or string in patterns: return True @@ -13,13 +19,15 @@ def match(patterns: Optional[List[str]], string: str) -> bool: # must not match for pattern in negatives: # matched a negative search - if re.match(pattern.replace("!", ""), string): + regex_pattern = _convert_glob_to_regex(pattern.replace("!", "")) + if re.match(regex_pattern, string): return False if positives: for pattern in positives: # match was found - if re.match(pattern, string): + regex_pattern = _convert_glob_to_regex(pattern) + if re.match(regex_pattern, string): return True # did not match any required paths