Fix Issue 11025 - case-insensitive backreferences in std.regex#11070
Fix Issue 11025 - case-insensitive backreferences in std.regex#11070niy-ati wants to merge 5 commits into
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).
| TestVectors( `[adzУ-Я]{4}`, "DzюЯ", "y", "$&", "DzюЯ", "i"), | ||
| TestVectors( `\p{L}\p{Lu}{10}`, "абвгдеЖЗИКЛ", "y", "$&", "абвгдеЖЗИКЛ", "i"), | ||
| TestVectors( `(?:Dåb){3}`, "DåbDÅBdÅb", "y", "$&", "DåbDÅBdÅb", "i"), | ||
| // Issue 11025: backrefs must casefold under /i |
There was a problem hiding this comment.
| // Issue 11025: backrefs must casefold under /i | |
| // https://github.com/dlang/phobos/issues/11025 backrefs must casefold under /i |
There was a problem hiding this comment.
updated the comment to link the issue.
| { | ||
| if (a == b) | ||
| return true; | ||
| foreach (c; simpleCaseFoldings(a)) |
There was a problem hiding this comment.
This is slow, see sicmp for how to do proper casefold compare with trie tables
|
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 |
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).