fix panic in analyze-string#13
Merged
Merged
Conversation
fix: fix panic in analyze-string with non-participating optional groups
When optional groups (e.g. `([0-9]{1,2})?`) don't participate in a
match, they produce zero-length group entries. For these entries, when
no parent group end-event exists at the same position, the start and
end events were inserted in the wrong order (end before start). This
caused `on_group_end()` to pop from an empty stack, panicking with
`unwrap()` on `None`.
Fix: swap the event insertion order in the `or_insert_with` branch
from `(-i, i)` to `(i, -i)`, matching the `and_modify` branch which
already inserts start before end.
Add regression test with regex `([0-9]{1,2})?\s?(...)?...\s?([0-9]{4})`
matching "1949" where groups 1 and 2 are optional and don't participate.
There was a problem hiding this comment.
Pull request overview
Fixes a panic in Regex::analyze when optional capturing groups don’t participate and end up represented as zero-length captures, by ensuring zero-length group “start/end” events are always inserted in a safe order.
Changes:
- Adjust event insertion order for zero-length capture groups to insert “start” before “end”, preventing
on_group_end()from popping an empty stack. - Add a regression test covering optional groups that don’t participate for a realistic date-like pattern.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
regexml/src/analyze_string.rs |
Fixes action ordering for zero-length group events in the or_insert_with path to avoid panics. |
regexml/tests/test_qt_analyze_string.rs |
Adds a regression test exercising optional non-participating groups to ensure analyze() no longer panics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
frankarensmeier
added a commit
to frankarensmeier/xee
that referenced
this pull request
Apr 28, 2026
Remove 10 now-passing tests from vendor/xslt-tests/filters: - analyze-string: 033, 034, 042, 077, 083, 095, 100 - position: 2201 - result-document: 1501, 1502 These pass thanks to: - regex-group() scoping fix for stylesheet functions (8b0d9ef) - regexml 0.2.2 fix for optional group panics (Paligo/regexml#13)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix panic in analyze-string with non-participating optional groups
When optional groups (e.g.
([0-9]{1,2})?) don't participate in a match, they produce zero-length group entries. For these entries, when no parent group end-event exists at the same position, the start and end events were inserted in the wrong order (end before start). This causedon_group_end()to pop from an empty stack, panicking withunwrap()onNone.Fix: swap the event insertion order in the
or_insert_withbranch from(-i, i)to(i, -i), matching theand_modifybranch which already inserts start before end.Add regression test with regex
([0-9]{1,2})?\s?(...)?...\s?([0-9]{4})matching "1949" where groups 1 and 2 are optional and don't participate.