Skip to content

Commit 729ffa4

Browse files
committed
fix: skip empty patterns in match_regex_list to prevent IndexError
match_regex_list indexes item_matcher[-1] to check for '$' suffix. An empty string pattern causes IndexError: string index out of range. This is reachable from CeleryIntegration.exclude_beat_tasks when user configures an empty string in the pattern list. Guard with if not item_matcher: continue before the index check. Fixes #6504
1 parent 9996734 commit 729ffa4

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

sentry_sdk/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,9 @@ def match_regex_list(
17361736
return False
17371737

17381738
for item_matcher in regex_list:
1739+
if not item_matcher:
1740+
continue
1741+
17391742
if not substring_matching and item_matcher[-1] != "$":
17401743
item_matcher += "$"
17411744

tests/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ 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], # empty pattern should not match
560+
["some-string", ["", "some-string"], True], # empty pattern skipped, second matches
561+
["some-string", ["", ""], False], # all empty patterns, no match
559562
],
560563
)
561564
def test_match_regex_list(item, regex_list, expected_result):

0 commit comments

Comments
 (0)