diff --git a/packages/router-core/src/utils.ts b/packages/router-core/src/utils.ts index f8fc8d56590..d6046ea37c9 100644 --- a/packages/router-core/src/utils.ts +++ b/packages/router-core/src/utils.ts @@ -595,6 +595,16 @@ export function escapeHtml(str: string): string { export function decodePath(path: string, decodeIgnore?: Array): string { if (!path) return path + + // Fast path: most paths are already decoded and safe. + // Only fall back to the slower scan/regex path when we see a '%' (encoded), + // a backslash (explicitly handled), a control character, or a protocol-relative + // prefix which needs collapsing. + // eslint-disable-next-line no-control-regex + if (!/[%\\\x00-\x1f\x7f]/.test(path) && !path.startsWith('//')) { + return path + } + const re = decodeIgnore ? new RegExp(`${decodeIgnore.join('|')}`, 'gi') : /%25|%5C/gi