-
Notifications
You must be signed in to change notification settings - Fork 50
Regex with positive lookahead crashes at runtime when accessing match.output #713
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This also reproduces with just Don't have a fix yet, but found the cause... The issue appears to be that a positive lookahead is implemented as:
The When you try to access the match output, the loss of that capture data causes a runtime failure, since any successful match must have both the overall range (empty in this case) and the capture formed during the lookahead (which is just the |
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.
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.
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.
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.
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.
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.
Description
Using a regex with a positive lookahead sometimes crashes @ runtime. See the example in the reproduction
Reproduction
Stack dump
Expected behavior
No crash
Environment
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: