diff --git a/src/utils/patches.ts b/src/utils/patches.ts index 53cf05dbc..70f1f3b5d 100644 --- a/src/utils/patches.ts +++ b/src/utils/patches.ts @@ -22,10 +22,10 @@ import { Patch, PatchReplacement, ReplaceFn } from "./types"; export function canonicalizeMatch(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) {