PatchHelper: Fix incorrect escape handling (#3194)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
sadan4 2025-12-27 19:04:00 -05:00 • committed by GitHub
parent 746f31e412
commit fcb8276a81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,7 +40,11 @@ export function canonicalizeMatch<T extends RegExp | string>(match: T): T {
return partialCanon as T;
}
const canonSource = partialCanon.replaceAll("\\i", String.raw`(?:[A-Za-z_$][\w$]*)`);
const canonSource = partialCanon.replaceAll(/(\\*)\\i/g, (match, leadingEscapes) =>
leadingEscapes.length % 2 === 0
? `${leadingEscapes}${String.raw`(?:[A-Za-z_$][\w$]*)`}`
: match.slice(1)
);
const canonRegex = new RegExp(canonSource, match.flags);
canonRegex.toString = match.toString.bind(match);