GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(utils): match_regex_list crashes on an empty-string pattern by devteamaegis · Pull Request #6505 · getsentry/sentry-python

Conversation

@devteamaegis

@devteamaegis devteamaegis commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

What's broken

match_regex_list checks item_matcher[-1] != "$" to decide whether to anchor each pattern. With the default substring_matching=False, an empty-string element makes ""[-1] raise:

>>> from sentry_sdk.utils import match_regex_list
>>> match_regex_list("anything", [""])
IndexError: string index out of range

exclude_beat_tasks in the Celery integration flows straight into this with the default mode, so an empty string in that user-supplied list crashes the beat instrumentation.

Why it happens

Indexing item_matcher[-1] on an empty string is out of range.

Fix

Short-circuit on empty: (not item_matcher or item_matcher[-1] != "$"). An empty matcher then becomes "$", which matches end-of-string — a sane result instead of a crash.

Test

Added a case asserting match_regex_list("anything", [""]) returns without raising; existing anchored/substring behavior is unchanged.

Fixes #6504

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sentry[bot] reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@devteamaegis
fix(utils): handle empty string in match_regex_list
d42a94a
@devteamaegis
devteamaegis requested a review from a team as a code owner June 4, 2026 18:03
ericapisani
ericapisani requested changes Jun 4, 2026
View reviewed changes

@ericapisani ericapisani left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the issue and pull request to address this.

There's a couple of things we'll need to address before this gets merged - let me know if you have any questions about what I've mentioned below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/test_utils.py Outdated

def test_match_regex_list_empty_string_pattern():
# An empty-string pattern must not raise IndexError (regression test).
result = match_regex_list("anything", [""])

@ericapisani ericapisani Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than have this be a standalone test, this case can be incorporated into the test above (test_match_regex_list) as one of the parameterized test cases. You'll just need to add the expected outcome as the last element in the array.

This means that last 2 assertions around foo/foobar can also be removed since we already have test cases that check similar behaviour within the array (lines 553 and 554 above)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread sentry_sdk/utils.py Outdated

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] != "$"):

@ericapisani ericapisani Jun 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this fixes the index error, the result that's returned from this change means match_regex_list("anything", [""]) will return True.

An empty string likely represents a typo/mistake on the developers part, and so we should treat this as if [] was passed in.

This would mean that this conditional should look like the following instead:

    for item_matcher in regex_list:
        if not item_matcher:
            return False

        if not substring_matching and item_matcher[-1] != "$":
            item_matcher += "$"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sentrivana sentrivana added the Waiting for: Community label Jun 8, 2026
@devteamaegis
devteamaegis force-pushed the fix/match-regex-list-empty-string branch from 4043b13 to d42a94a Compare June 11, 2026 19:44
cursor[bot]
cursor Bot reviewed Jun 11, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d42a94a. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread sentry_sdk/utils.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

sentry[bot]
sentry Bot reviewed Jun 11, 2026
View reviewed changes
Comment thread sentry_sdk/utils.py Outdated
Comment on lines 1743 to 1744
if not substring_matching and (not item_matcher or item_matcher[-1] != "$"):
item_matcher += "$"

@sentry sentry Bot Jun 11, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: An empty string "" in regex_list causes match_regex_list to always return True. The fix item_matcher += "$" is incorrect as re.search("$", ...) always matches.
Severity: HIGH

Suggested Fix

Instead of converting an empty item_matcher to "$", the function should explicitly handle an empty string in regex_list to mean "match nothing". This could be done by returning False immediately if item_matcher is empty after processing, or by ensuring the regex pattern for an empty string does not match everything.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: sentry_sdk/utils.py#L1743-L1744

Potential issue: The function `match_regex_list` incorrectly handles an empty string
`""` in `regex_list`. The proposed fix converts an empty `item_matcher` to `"$"` before
performing a regex search. However, `re.search("$", item)` always returns a match
because the `$` metacharacter matches the end-of-string position, which is present in
every string. As a result, if any `regex_list` contains an empty string, the function
will incorrectly return `True` for all items. For example, setting `exclude_beat_tasks =
[""]` in the Celery integration would silently exclude all beat tasks from
instrumentation.

Also affects:

  • sentry_sdk/integrations/celery/beat.py:130

Did we get this right? 👍 / 👎 to inform future reviews.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devteamaegis
fix(utils): treat empty-string pattern like empty list in match_regex…
27447a4
…_list

Address review feedback: an empty string in regex_list represents a
typo/mistake and should be treated as if [] was passed, returning False
rather than matching every item. Fold the regression case into the
parameterized test_match_regex_list cases and drop the redundant
standalone test.
@getsantry

getsantry Bot commented Jul 3, 2026

Copy link
Copy Markdown

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@getsantry getsantry Bot added the Stale label Jul 3, 2026
@getsantry

getsantry Bot commented Jul 25, 2026

Copy link
Copy Markdown

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devteamaegis

devteamaegis commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @ericapisani — both points addressed.

  1. Empty-pattern handling: adopted your suggested conditional, so an empty item_matcher now hits return False before the anchoring logic. match_regex_list("anything", [""]) returns False (treated like []) instead of matching everything, which also resolves the Bugbot finding about re.search("$", ...) always matching and the exclude_beat_tasks fallout.
  2. Test: folded the case into the parameterized test_match_regex_list as ["some-string", [""], False] and removed the standalone test plus the redundant foo/foobar assertions already covered by existing cases.

Verified the empty-string list now returns False while normal patterns still match. Let me know if you'd like anything else.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb

alexander-alderman-webb commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of #6896

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb alexander-alderman-webb closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sentry sentry[bot] sentry[bot] left review comments
@cursor cursor[bot] cursor[bot] left review comments
@ericapisani ericapisani ericapisani requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Stale Waiting for: Community

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

match_regex_list raises IndexError when a pattern list contains an empty string

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@devteamaegis @alexander-alderman-webb @ericapisani @sentrivana
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.