Skip to content

Commit 27447a4

Browse files
committed
fix(utils): treat empty-string pattern like empty list in match_regex_list
Address review feedback: an empty string in regex_list represents a typo/mistake and should be treated as if [] was passed, returning False rather than matching every item. Fold the regression case into the parameterized test_match_regex_list cases and drop the redundant standalone test.
1 parent d42a94a commit 27447a4

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

sentry_sdk/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,10 @@ def match_regex_list(
17401740
return False
17411741

17421742
for item_matcher in regex_list:
1743-
if not substring_matching and (not item_matcher or item_matcher[-1] != "$"):
1743+
if not item_matcher:
1744+
return False
1745+
1746+
if not substring_matching and item_matcher[-1] != "$":
17441747
item_matcher += "$"
17451748

17461749
matched = re.search(item_matcher, item)

tests/test_utils.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,13 @@ def test_include_source_context_when_serializing_frame(include_source_context):
556556
["some-string", ["some.*"], True],
557557
["some-string", ["Some"], False], # we do case sensitive matching
558558
["some-string", [".*string$"], True],
559+
["some-string", [""], False], # an empty-string pattern is treated like []
559560
],
560561
)
561562
def test_match_regex_list(item, regex_list, expected_result):
562563
assert match_regex_list(item, regex_list) == expected_result
563564

564565

565-
def test_match_regex_list_empty_string_pattern():
566-
# An empty-string pattern must not raise IndexError (regression test).
567-
result = match_regex_list("anything", [""])
568-
assert isinstance(result, bool)
569-
assert match_regex_list("foobar", ["foo"]) is False
570-
assert match_regex_list("foo", ["foo"]) is True
571-
572-
573566
@pytest.mark.parametrize(
574567
"version,expected_result",
575568
[

0 commit comments

Comments
 (0)