From 729ffa4cfbea629917b2d423b0264701d5630668 Mon Sep 17 00:00:00 2001 From: ncttjz Date: Sun, 19 Jul 2026 19:32:07 +0700 Subject: [PATCH] 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 --- sentry_sdk/utils.py | 3 +++ tests/test_utils.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 5aa533dea0..103e380e9a 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1736,6 +1736,9 @@ def match_regex_list( return False for item_matcher in regex_list: + if not item_matcher: + continue + if not substring_matching and item_matcher[-1] != "$": item_matcher += "$" diff --git a/tests/test_utils.py b/tests/test_utils.py index 718cdbaa1d..41c5d2f4c0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -556,6 +556,9 @@ def test_include_source_context_when_serializing_frame(include_source_context): ["some-string", ["some.*"], True], ["some-string", ["Some"], False], # we do case sensitive matching ["some-string", [".*string$"], True], + ["some-string", [""], False], # empty pattern should not match + ["some-string", ["", "some-string"], True], # empty pattern skipped, second matches + ["some-string", ["", ""], False], # all empty patterns, no match ], ) def test_match_regex_list(item, regex_list, expected_result):