fix bug in canonicalizing #{intl::foo::hash}

Co-Authored-By: sadan4 <117494111+sadan4@users.noreply.github.com>
This commit is contained in:
thororen1234 2026-03-31 22:28:35 -04:00
parent ffbb6b1960
commit 0e59e55582
No known key found for this signature in database

View file

@ -22,10 +22,10 @@ import { Patch, PatchReplacement, ReplaceFn } from "./types";
export function canonicalizeMatch<T extends RegExp | string>(match: T): T {
let partialCanon = typeof match === "string" ? match : match.source;
partialCanon = partialCanon.replaceAll(/#{intl::([\w$+/]*)(?:::(\w+))?}/g, (_, key, modifier) => {
const hashed = modifier === "raw" ? key : runtimeHashMessageKey(key);
if (modifier === "hash") return hashed;
const isString = typeof match === "string";
const hashed = modifier === "raw" ? key : runtimeHashMessageKey(key);
if (modifier === "hash") return isString ? hashed : String.raw`(?:${hashed})`.replaceAll("+", "\\+");
const hasSpecialChars = !Number.isNaN(Number(hashed[0])) || hashed.includes("+") || hashed.includes("/");
if (hasSpecialChars) {