Skip to content

Commit 4043b13

Browse files
Ishaan SamantrayIshaan Samantray
authored andcommitted
fix(utils): handle empty string in match_regex_list
1 parent 2ce26d1 commit 4043b13

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

sentry_sdk/utils.py

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

17421742
for item_matcher in regex_list:
1743-
if not substring_matching and item_matcher[-1] != "$":
1743+
if not substring_matching and (not item_matcher or item_matcher[-1] != "$"):
17441744
item_matcher += "$"
17451745

17461746
matched = re.search(item_matcher, item)

tests/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,14 @@ def test_match_regex_list(item, regex_list, expected_result):
562562
assert match_regex_list(item, regex_list) == expected_result
563563

564564

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+
565573
@pytest.mark.parametrize(
566574
"version,expected_result",
567575
[

0 commit comments

Comments
 (0)