-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flag effect remains active outside of current group #640
Comments
This fixes a rather nasty bug where flags set inside a group were being applies to expressions outside the group. e.g., In the simplest case, `((?i)a)b)` would match `aB`, even though the case insensitive flag _shouldn't_ be applied to `b`. The issue here was that we were actually going out of our way to reset the flags when a group is popped only _some_ of the time. Namely, when flags were set via `(?i:a)b` syntax. Instead, flags should be reset to their previous state _every_ time a group is popped in the translator. The fix here is pretty simple. When we open a group, if the group itself does not have any flags, then we simply record the current state of the flags instead of trying to replace the current flags. Then, when we pop the group, we are guaranteed to obtain the old flags, at which point, we reset them. Fixes #640
Yeesh. What a bug. This is definitely wrong. Interestingly, the code was actually going out of its way not to reset flags in this case. I'm not sure why. I don't think I ever intended for this behavior, and no tests were checking for it. And as you say, the docs seem to pretty strongly contradict the current behavior. I have a fix up. Thanks for reporting this! |
This fixes a rather nasty bug where flags set inside a group were being applies to expressions outside the group. e.g., In the simplest case, `((?i)a)b)` would match `aB`, even though the case insensitive flag _shouldn't_ be applied to `b`. The issue here was that we were actually going out of our way to reset the flags when a group is popped only _some_ of the time. Namely, when flags were set via `(?i:a)b` syntax. Instead, flags should be reset to their previous state _every_ time a group is popped in the translator. The fix here is pretty simple. When we open a group, if the group itself does not have any flags, then we simply record the current state of the flags instead of trying to replace the current flags. Then, when we pop the group, we are guaranteed to obtain the old flags, at which point, we reset them. Fixes #640
This brings in the bug fix for #640 for flag scoping.
Notably, this brings in a bug fix reported by @okdana: rust-lang/regex#640
OK, this should be fixed in |
Thanks! |
…messages This regex was relying on a bug with flag scoping that was fixed (rust-lang/regex#640) in regex 1.3.4.
…r messages This regex was relying on a bug with flag scoping that was fixed (rust-lang/regex#640) in regex 1.3.4.
The
regex
documentation suggests that flags ((?foo)
) only apply within the 'current group', which would match the behaviour of Perl and PCRE, but that doesn't seem to be the case:(My test case uses ripgrep 11.0.2 from Homebrew, but i've confirmed that it works the same way if i compile a simple test app with
regex
1.3.3.)Am i misunderstanding something, or is this wrong?
The text was updated successfully, but these errors were encountered: