From 4043b13f07841274361754053792c1352fdd6b5a Mon Sep 17 00:00:00 2001 From: Ishaan Samantray Date: Thu, 4 Jun 2026 14:03:14 -0400 Subject: [PATCH] fix(utils): handle empty string in match_regex_list --- sentry_sdk/utils.py | 2 +- tests/test_utils.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 875d28c0d0..41eef5c35f 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1740,7 +1740,7 @@ def match_regex_list( return False for item_matcher in regex_list: - if not substring_matching and item_matcher[-1] != "$": + if not substring_matching and (not item_matcher or item_matcher[-1] != "$"): item_matcher += "$" matched = re.search(item_matcher, item) diff --git a/tests/test_utils.py b/tests/test_utils.py index 718cdbaa1d..4a5b7235c2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -562,6 +562,14 @@ def test_match_regex_list(item, regex_list, expected_result): assert match_regex_list(item, regex_list) == expected_result +def test_match_regex_list_empty_string_pattern(): + # An empty-string pattern must not raise IndexError (regression test). + result = match_regex_list("anything", [""]) + assert isinstance(result, bool) + assert match_regex_list("foobar", ["foo"]) is False + assert match_regex_list("foo", ["foo"]) is True + + @pytest.mark.parametrize( "version,expected_result", [