Fix Issue 11025 - case-insensitive backreferences in std.regex - #11070
Conversation
Under /i, literals are casefolded at parse time but IR.Backref still compared codepoints with ==. Use simple case folding when matching backrefs in the backtracking and Thompson engines (and ctRegex).
|
What I meant was not using sicmp as is but getting its internal compare function and using that to compare two dchar case-insensitively. Plain call to sicmp brings its own overheads which are not acceptable. |
|
Thanks for the clarification , |
|
LGTM |
|
Literals are folded at parse time using the flag active at their position, but a backref here uses one global flag for the entire pattern. // over-match: (?i) appears *after* the backref, so \1 should stay case-sensitive
assert( matchFirst("Aax", regex(`(.)\1(?i)X`)).empty); // fails: matches "Aax"
// under-match: casefold is on at \1 but cleared before X
assert(!matchFirst("AaX", regex(`(?i)(.)\1(?-i)X`)).empty); // fails: no match |
|
The way out is adding a new opcode for caseinsensitive backreference |
|
Addressed the inline @kubo39 , backrefs now follow the same per-position casefold as literals ( |
|
LGTM |
|
@rikkimax whenever you have a moment pls review it, open to address anything else. |
I have nothing to add std.regex isn't really my area. But I do get to say that I'd love for someone to finish case handling in std.uni with the same vigor! Would be very helpful to get that finished before PhobosV3 so I don't have to deal with that. |
|
FreeBSD 14.4 failed during pkg install (mpdecimal fetch / disk write) before the suite ran. Other checks are green , could someone re-run the failed FreeBSD job? |
|
@niy-ati see also dlang/ci#497 |
0xEAB
left a comment
There was a problem hiding this comment.
- LGTM
- Passes testsuite.
- Does not remove or alter any tests.
- Adds new tests.
- Has code owner’s approval: #11070 (comment)
- I’ve added nitpick format changes.
Summary
/i,IR.Backrefcompared captures with==, so(.)\1matchedBBbut notAa.RegexOption.casefoldis set (backtracking, Thompson, and ctRegex).Fixes #11025
Test plan
TestVectorsforAa/aA/BB/ non-match / multi-char /(?i).