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: Avoid `IndexError` in `match_regex_list()` by alexander-alderman-webb · Pull Request #6896 · getsentry/sentry-python

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Jul 28, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator

Description

This approach still allows matching empty strings.

Issues

Closes #6504

Reminders

  • Please add tests to validate your changes, and lint your code using uv run ruff.
  • Add GH Issue ID & Linear ID (if applicable)
  • PR title should use conventional commit style (feat:, fix:, ref:, meta:)
  • For external contributors: CONTRIBUTING.md, Sentry SDK development docs, Discord community

Sorry, something went wrong.

Uh oh!

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

All reactions
@alexander-alderman-webb
fix: Avoid IndexError in match_regex_list()
a01cef7
This was referenced Jul 28, 2026
fix: skip empty patterns in match_regex_list to prevent IndexError #6842
Closed
fix(utils): match_regex_list crashes on an empty-string pattern #6505
Closed
fix(match_regex_list): handle empty string patterns without IndexError #6802
Closed
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review July 28, 2026 07:45
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner July 28, 2026 07:45
sentry[bot]
sentry Bot reviewed Jul 28, 2026
View reviewed changes
Comment thread sentry_sdk/utils.py
Comment on lines +1739 to 1740
if not substring_matching and (not item_matcher or item_matcher[-1] != "$"):
item_matcher += "$"

@sentry sentry Bot Jul 28, 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: The fix for an IndexError causes an empty string in regex_list to be treated as a pattern that matches everything, leading to unintended consequences.
Severity: HIGH

Suggested Fix

The function match_regex_list should handle empty strings in regex_list explicitly. Instead of converting "" to "$", it should either skip empty strings (possibly with a warning) or only match them against empty input strings. This will prevent the unintended "match-all" behavior.

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#L1739-L1740

Potential issue: The change in `match_regex_list` prevents an `IndexError` when an item
in `regex_list` is an empty string. However, it introduces a new issue. An empty string
pattern `""` is converted to `"$"` which, when used with `re.search`, matches the end of
any string. Consequently, if a configuration list like `trace_propagation_targets` or
`exclude_beat_tasks` contains an empty string, `match_regex_list` will return `True` for
every input. This could lead to all HTTP requests having trace propagation enabled, or
all Celery beat tasks being excluded from monitoring, failing silently instead of
crashing.

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.

alexander-alderman-webb reacted with thumbs down emoji
All reactions
  • 👎 1 reaction

@alexander-alderman-webb alexander-alderman-webb Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

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.

that's what I would expect with an empty regex

Sorry, something went wrong.

Uh oh!

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

All reactions
@alexander-alderman-webb alexander-alderman-webb mentioned this pull request Jul 28, 2026
fix: handle empty string in match_regex_list to prevent IndexError #6509
Closed
2 tasks done
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ 98739 passed | ❌ 2 failed | ⏭️ 6806 skipped | Total: 105547 | Pass Rate: 93.55% | Execution Time: 359m 31s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +52
Passed Tests 📈 +51
Failed Tests 📈 +1
Skipped Tests —

➕ New Tests (2)

View new tests
  • test_cache_spans_get_span_name[True-get-args4-kwargs4-]
    • File: tests.integrations.django.test_cache_module
    • Status: ❌ Failing
  • test_cache_spans_get_span_name[False-get-args4-kwargs4-]
    • File: tests.integrations.django.test_cache_module
    • Status: ❌ Failing

➖ Removed Tests (1)

View removed tests
  • test_continuous_profiler_auto_start_and_stop_sampled[experiment-thread]
    • File: tests.profiler.test_continuous_profiler

❌ Failed Tests

test_cache_spans_get_span_name[True-get-args4-kwargs4-]

File: tests.integrations.django.test_cache_module
Suite: py3.12-django-v6.0.6
Error: AssertionError: assert 'U\x1bvB8yI궖4Th\x02%t' == '' + U#x1BvB8yI궖4Th#x02%t

Stack Trace
tests/integrations/django/test_cache_module.py:578: in test_cache_spans_get_span_name
    assert _get_span_description(method_name, args, kwargs) == expected_name
E   AssertionError: assert 'U\x1bvB8yI궖4Th\x02%t' == ''
E     
E     + U#x1BvB8yI궖4Th#x02%t

test_cache_spans_get_span_name[False-get-args4-kwargs4-]

File: tests.integrations.django.test_cache_module
Suite: py3.12-django-v6.0.6
Error: AssertionError: assert 'U\x1bvB8yI궖4Th\x02%t' == '' + U#x1BvB8yI궖4Th#x02%t

Stack Trace
tests/integrations/django/test_cache_module.py:578: in test_cache_spans_get_span_name
    assert _get_span_description(method_name, args, kwargs) == expected_name
E   AssertionError: assert 'U\x1bvB8yI궖4Th\x02%t' == ''
E     
E     + U#x1BvB8yI궖4Th#x02%t

✅ Patch coverage is 100.00%. Project has 2558 uncovered lines.
✅ Project coverage is 89.57%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.56%    89.57%    +0.01%
==========================================
  Files          193       193         —
  Lines        24531     24531         —
  Branches      8678      8678         —
==========================================
+ Hits         21971     21973        +2
- Misses        2560      2558        -2
- Partials      1400      1398        -2

Generated by Codecov Action

All reactions

Sorry, something went wrong.

Uh oh!

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

Chenghao999
Chenghao999 reviewed Aug 6, 2026
View reviewed changes

@Chenghao999 Chenghao999 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.

Good minimal fix for the crash. One semantic point to consider: with this change an empty matcher becomes "$", and re.search("$", item) matches every string — so if regex_list ever contains an empty pattern, match_regex_list will now return True for any item instead of crashing. If an empty pattern should be ignored rather than match everything, an explicit if not item_matcher: continue would express that intent.

I also checked the substring_matching path: it only appends/reads the tail, no equivalent item_matcher[0] access, so this is the only crash site. LGTM otherwise.

Sorry, something went wrong.

Uh oh!

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

All reactions

This branch has not been deployed

No deployments
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
+1 more reviewer
@Chenghao999 Chenghao999 Chenghao999 left review comments
Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

2 participants

@alexander-alderman-webb @Chenghao999
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 01402503 — 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.