Skip to content

Conversation

@natecook1000
Copy link
Member

Explanation: This resolves an issue where matching a pattern that includes a capture group inside a positive lookahead or an atomic group results in a runtime error.
Scope: All the changes are internal implementation within the _StringProcessing module.
Issue: rdar://126009544
Original PR: #723
Risk: Low. There's no API or ABI impact of this change.
Testing: This change adds tests that verify that the previously failing patterns are working correctly, and continues to pass the existing compilation and pattern-matching tests.
Reviewer: @stephentyrone


Cherry pick to swift/release/6.0 of #723.

This fixes an issue where capture groups inside a positive lookahead
were being reset even upon successful matching of the lookahead. For
example, with the pattern `/(?=(\d))/`, matching against a string like
`"abc1"` should result in the output `("", "1")`. However, accessing
the output traps instead, since the range data for capture 1 is
missing even on success.

This change resolves the issue by adding a boolean payload to the
`fail` instruction that indicates whether to preserve captures when
resetting the matching state, which allows any captures inside a
lookahead to persist after success.

Fixes #713.
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 3c4a872 into swift/release/6.0 Apr 17, 2024
@natecook1000 natecook1000 deleted the swift6-allow-lookahead-captures branch April 17, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants