gh-155985: Do not fuse a set difference under IGNORECASE with LOCALE - #155993
Open
fedonman wants to merge 1 commit into
Open
gh-155985: Do not fuse a set difference under IGNORECASE with LOCALE#155993fedonman wants to merge 1 commit into
fedonman wants to merge 1 commit into
Conversation
…OCALE _fuse_difference() rewrites <flat charset A> (?<![B]) into the single charset [NEGATE] B [NEGATE] A. That is sound where the engine walks a set once, but SRE(charset_loc_ignore) walks it twice, once with the lowercased character and once with the uppercased one, and matches if either walk does. The second walk starts with the NEGATE polarity reset, so a character that matches B in one case and A in the other escapes the subtraction. The pass did not see the compile flags, so it could not tell the two apart. Thread the effective flags through optimize() and _walk(), combining them for a scoped group, and skip the fusion when IGNORECASE and LOCALE are both set, the condition _compiler.py already uses to emit IN_LOC_IGNORE.
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.
_fuse_difference()now sees the compile flags and skips the fusion whenIGNORECASEandLOCALEare both set, which is exactly when the fused set would compile toIN_LOC_IGNORE. The flags are threaded throughoptimize()and_walk()and recombined for a scoped group, so(?i:...)inside are.LOCALEpattern is covered too.No NEWS fragment: the fusion landed earlier in this cycle (GH-152214) and has never been in a release, so there is nothing a user could have hit.
re.IGNORECASE | re.LOCALE#155985