Skip to content

gh-155985: Do not fuse a set difference under IGNORECASE with LOCALE - #155993

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-re-fuse-difference-locale
Open

gh-155985: Do not fuse a set difference under IGNORECASE with LOCALE#155993
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-re-fuse-difference-locale

Conversation

@fedonman

@fedonman fedonman commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

_fuse_difference() now sees the compile flags and skips the fusion when IGNORECASE and LOCALE are both set, which is exactly when the fused set would compile to IN_LOC_IGNORE. The flags are threaded through optimize() and _walk() and recombined for a scoped group, so (?i:...) inside a re.LOCALE pattern is covered too.

$ ./python -m test test_re

Total duration: 1.3 sec
Total tests: run=170 skipped=3
Total test files: run=1/1
Result: SUCCESS

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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant