Skip to content

Commit b710e13

Browse files
author
Wahaj Ahmed
committed
fix: handle empty string in match_regex_list to prevent IndexError
When match_regex_list receives a pattern list containing an empty string, item_matcher[-1] raises IndexError because empty strings have no characters. This is reachable from the Celery integration when CeleryIntegration.exclude_beat_tasks contains an empty string. Fix: skip empty strings in the iteration loop before the [-1] access. Fixes: #6504 Signed-off-by: Wahaj Ahmed <wahaj.ahmed010@gmail.com>
1 parent 5ce5d1a commit b710e13

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

sentry_sdk/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,8 @@ def match_regex_list(
17401740
return False
17411741

17421742
for item_matcher in regex_list:
1743+
if not item_matcher:
1744+
continue
17431745
if not substring_matching and item_matcher[-1] != "$":
17441746
item_matcher += "$"
17451747

tests/test_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ 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 string in list should not crash
560+
["", [""], False], # both empty should not crash
559561
],
560562
)
561563
def test_match_regex_list(item, regex_list, expected_result):

0 commit comments

Comments
 (0)