@tanstack/router-core 1.134.12 → 1.134.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/RouterProvider.d.cts +1 -1
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/path.cjs +1 -1
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/router.cjs +14 -3
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/utils.cjs +24 -29
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -1
- package/dist/esm/RouterProvider.d.ts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/path.js +2 -2
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/router.js +15 -4
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js +24 -29
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/RouterProvider.ts +1 -1
- package/src/index.ts +1 -0
- package/src/path.ts +2 -2
- package/src/router.ts +15 -4
- package/src/utils.ts +43 -44
package/dist/esm/utils.js
CHANGED
|
@@ -164,49 +164,44 @@ function findLast(array, predicate) {
|
|
|
164
164
|
const DECODE_IGNORE_LIST = Array.from(
|
|
165
165
|
(/* @__PURE__ */ new Map([
|
|
166
166
|
["%", "%25"],
|
|
167
|
-
["\\", "%5C"]
|
|
168
|
-
["/", "%2F"],
|
|
169
|
-
[";", "%3B"],
|
|
170
|
-
[":", "%3A"],
|
|
171
|
-
["@", "%40"],
|
|
172
|
-
["&", "%26"],
|
|
173
|
-
["=", "%3D"],
|
|
174
|
-
["+", "%2B"],
|
|
175
|
-
["$", "%24"],
|
|
176
|
-
[",", "%2C"]
|
|
167
|
+
["\\", "%5C"]
|
|
177
168
|
])).values()
|
|
178
169
|
);
|
|
179
|
-
function
|
|
180
|
-
function
|
|
170
|
+
function decodePath(part, decodeIgnore = DECODE_IGNORE_LIST) {
|
|
171
|
+
function splitAndDecode(part2, decodeIgnore2, startIndex = 0) {
|
|
172
|
+
for (let i = startIndex; i < decodeIgnore2.length; i++) {
|
|
173
|
+
const char = decodeIgnore2[i].toUpperCase();
|
|
174
|
+
if (part2.includes(char)) {
|
|
175
|
+
const partsToDecode = part2.split(char);
|
|
176
|
+
const partsToJoin = [];
|
|
177
|
+
for (const partToDecode of partsToDecode) {
|
|
178
|
+
partsToJoin.push(splitAndDecode(partToDecode, decodeIgnore2, i + 1));
|
|
179
|
+
}
|
|
180
|
+
return partsToJoin.join(char);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
181
183
|
try {
|
|
182
|
-
return
|
|
184
|
+
return decodeURI(part2);
|
|
183
185
|
} catch {
|
|
184
|
-
return part2.replaceAll(/%[0-9A-
|
|
186
|
+
return part2.replaceAll(/%[0-9A-F]{2}/g, (match) => {
|
|
185
187
|
try {
|
|
186
|
-
return
|
|
188
|
+
return decodeURI(match);
|
|
187
189
|
} catch {
|
|
188
190
|
return match;
|
|
189
191
|
}
|
|
190
192
|
});
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
|
-
if (part === "" ||
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
for (const partToDecode of partsToDecode) {
|
|
200
|
-
partsToJoin.push(decodePathSegment(partToDecode, decodeIgnore, i + 1));
|
|
201
|
-
}
|
|
202
|
-
return partsToJoin.join(char);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return decode(part);
|
|
195
|
+
if (part === "" || !/%[0-9A-Fa-f]{2}/g.test(part)) return part;
|
|
196
|
+
const normalizedPart = part.replaceAll(
|
|
197
|
+
/%[0-9a-f]{2}/g,
|
|
198
|
+
(match) => match.toUpperCase()
|
|
199
|
+
);
|
|
200
|
+
return splitAndDecode(normalizedPart, decodeIgnore);
|
|
206
201
|
}
|
|
207
202
|
export {
|
|
208
203
|
createControlledPromise,
|
|
209
|
-
|
|
204
|
+
decodePath,
|
|
210
205
|
deepEqual,
|
|
211
206
|
findLast,
|
|
212
207
|
functionalUpdate,
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import type { RouteIds } from './routeInfo'\nimport type { AnyRouter } from './router'\n\nexport type Awaitable<T> = T | Promise<T>\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\n\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type PickOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = keyof TLeft &\n keyof TRight extends never\n ? TRight\n : Omit<TRight, keyof TLeft & keyof TRight> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n }\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type IsNonEmptyObject<T> = T extends object\n ? keyof T extends never\n ? false\n : true\n : false\n\nexport type Assign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : keyof TLeft & keyof TRight extends never\n ? TLeft & TRight\n : Omit<TLeft, keyof TRight> & TRight\n : never\n : never\n\nexport type IntersectAssign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : TRight & TLeft\n : never\n : never\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive\n ? never\n : TUnion\n\nexport type PartialMergeAllObject<TUnion> =\n ExtractObjects<TUnion> extends infer TObj\n ? [TObj] extends [never]\n ? never\n : {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeAllPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n | undefined\n | null\n\nexport type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type PartialMergeAll<TUnion> =\n | ExtractPrimitives<TUnion>\n | PartialMergeAllObject<TUnion>\n\nexport type Constrain<T, TConstraint, TDefault = TConstraint> =\n | (T extends TConstraint ? T : never)\n | TDefault\n\nexport type ConstrainLiteral<T, TConstraint, TDefault = TConstraint> =\n | (T & TConstraint)\n | TDefault\n\n/**\n * To be added to router types\n */\nexport type UnionToIntersection<T> = (\n T extends any ? (arg: T) => any : never\n) extends (arg: infer T) => any\n ? T\n : never\n\n/**\n * Merges everything in a union into one object.\n * This mapped type is homomorphic which means it preserves stuff! :)\n */\nexport type MergeAllObjects<\n TUnion,\n TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,\n> = [keyof TIntersected] extends [never]\n ? never\n : {\n [TKey in keyof TIntersected]: TUnion extends any\n ? TUnion[TKey & keyof TUnion]\n : never\n }\n\nexport type MergeAll<TUnion> =\n | MergeAllObjects<TUnion>\n | ExtractPrimitives<TUnion>\n\nexport type ValidateJSON<T> = ((...args: Array<any>) => any) extends T\n ? unknown extends T\n ? never\n : 'Function is not serializable'\n : { [K in keyof T]: ValidateJSON<T[K]> }\n\nexport type LooseReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn\n : never\n\nexport type LooseAsyncReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn extends Promise<infer TReturn>\n ? TReturn\n : TReturn\n : never\n\n/**\n * Return the last element of an array.\n * Intended for non-empty arrays used within router internals.\n */\nexport function last<T>(arr: Array<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\n/**\n * Apply a value-or-updater to a previous value.\n * Accepts either a literal value or a function of the previous value.\n */\nexport function functionalUpdate<TPrevious, TResult = TPrevious>(\n updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>,\n previous: TPrevious,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nconst hasOwn = Object.prototype.hasOwnProperty\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (!array && !(isPlainObject(prev) && isPlainObject(next))) return next\n\n const prevItems = array ? prev : getEnumerableOwnKeys(prev)\n if (!prevItems) return next\n const nextItems = array ? next : getEnumerableOwnKeys(next)\n if (!nextItems) return next\n const prevSize = prevItems.length\n const nextSize = nextItems.length\n const copy: any = array ? new Array(nextSize) : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : (nextItems[i] as any)\n const p = prev[key]\n const n = next[key]\n\n if (p === n) {\n copy[key] = p\n if (array ? i < prevSize : hasOwn.call(prev, key)) equalItems++\n continue\n }\n\n if (\n p === null ||\n n === null ||\n typeof p !== 'object' ||\n typeof n !== 'object'\n ) {\n copy[key] = n\n continue\n }\n\n const v = replaceEqualDeep(p, n)\n copy[key] = v\n if (v === p) equalItems++\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n}\n\n/**\n * Equivalent to `Reflect.ownKeys`, but ensures that objects are \"clone-friendly\":\n * will return false if object has any non-enumerable properties.\n */\nfunction getEnumerableOwnKeys(o: object) {\n const keys = []\n const names = Object.getOwnPropertyNames(o)\n for (const name of names) {\n if (!Object.prototype.propertyIsEnumerable.call(o, name)) return false\n keys.push(name)\n }\n const symbols = Object.getOwnPropertySymbols(o)\n for (const symbol of symbols) {\n if (!Object.prototype.propertyIsEnumerable.call(o, symbol)) return false\n keys.push(symbol)\n }\n return keys\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\n/**\n * Check if a value is a \"plain\" array (no extra enumerable keys).\n */\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n/**\n * Perform a deep equality check with options for partial comparison and\n * ignoring `undefined` values. Optimized for router state comparisons.\n */\nexport function deepEqual(\n a: any,\n b: any,\n opts?: { partial?: boolean; ignoreUndefined?: boolean },\n): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false\n for (let i = 0, l = a.length; i < l; i++) {\n if (!deepEqual(a[i], b[i], opts)) return false\n }\n return true\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const ignoreUndefined = opts?.ignoreUndefined ?? true\n\n if (opts?.partial) {\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n if (!deepEqual(a[k], b[k], opts)) return false\n }\n }\n return true\n }\n\n let aCount = 0\n if (!ignoreUndefined) {\n aCount = Object.keys(a).length\n } else {\n for (const k in a) {\n if (a[k] !== undefined) aCount++\n }\n }\n\n let bCount = 0\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n bCount++\n if (bCount > aCount || !deepEqual(a[k], b[k], opts)) return false\n }\n }\n\n return aCount === bCount\n }\n\n return false\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true\n ? T\n : T | undefined\n\nexport type StrictOrFrom<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>\n strict?: TStrict\n }\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n value?: T\n}\n\n/**\n * Create a promise with exposed resolve/reject and status fields.\n * Useful for coordinating async router lifecycle operations.\n */\nexport function createControlledPromise<T>(onResolve?: (value: T) => void) {\n let resolveLoadPromise!: (value: T) => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<T>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = (value: T) => {\n controlledPromise.status = 'resolved'\n controlledPromise.value = value\n resolveLoadPromise(value)\n onResolve?.(value)\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Heuristically detect dynamic import \"module not found\" errors\n * across major browsers for lazy route component handling.\n */\nexport function isModuleNotFoundError(error: any): boolean {\n // chrome: \"Failed to fetch dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // firefox: \"error loading dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // safari: \"Importing a module script failed.\"\n if (typeof error?.message !== 'string') return false\n return (\n error.message.startsWith('Failed to fetch dynamically imported module') ||\n error.message.startsWith('error loading dynamically imported module') ||\n error.message.startsWith('Importing a module script failed')\n )\n}\n\nexport function isPromise<T>(\n value: Promise<Awaited<T>> | T,\n): value is Promise<Awaited<T>> {\n return Boolean(\n value &&\n typeof value === 'object' &&\n typeof (value as Promise<T>).then === 'function',\n )\n}\n\nexport function findLast<T>(\n array: ReadonlyArray<T>,\n predicate: (item: T) => boolean,\n): T | undefined {\n for (let i = array.length - 1; i >= 0; i--) {\n const item = array[i]!\n if (predicate(item)) return item\n }\n return undefined\n}\n\nconst DECODE_IGNORE_LIST = Array.from(\n new Map([\n ['%', '%25'],\n ['\\\\', '%5C'],\n ['/', '%2F'],\n [';', '%3B'],\n [':', '%3A'],\n ['@', '%40'],\n ['&', '%26'],\n ['=', '%3D'],\n ['+', '%2B'],\n ['$', '%24'],\n [',', '%2C'],\n ]).values(),\n)\n\nexport function decodePathSegment(\n part: string,\n decodeIgnore: Array<string> = DECODE_IGNORE_LIST,\n startIndex = 0,\n): string {\n function decode(part: string): string {\n try {\n return decodeURIComponent(part)\n } catch {\n // if the decoding fails, try to decode the various parts leaving the malformed tags in place\n return part.replaceAll(/%[0-9A-Fa-f]{2}/g, (match) => {\n try {\n return decodeURIComponent(match)\n } catch {\n return match\n }\n })\n }\n }\n\n // if the path segment does not contain any encoded uri components return the path as is\n if (part === '' || !part.match(/%[0-9A-Fa-f]{2}/g)) return part\n\n // decode the path / path segment by splitting it into parts defined by the ignore list.\n // once these pieces have been decoded, join them back together to form the final decoded path segment with the ignored character in place.\n // we walk through the ignore list linearly, breaking the segment up into pieces and decoding each piece individually.\n // use index traversal to avoid making unnecessary copies of the array.\n for (let i = startIndex; i < decodeIgnore.length; i++) {\n const char = decodeIgnore[i]\n\n // check if the part includes the current ignore character\n // if it doesn't continue to the next ignore character\n if (char && part.includes(char)) {\n // split the part into pieces that needs to be checked and decoded\n const partsToDecode = part.split(char)\n const partsToJoin: Array<string> = []\n\n // now check and decode each piece individually taking into consideration the remaining ignored characters.\n // since we are walking through the list linearly, we only need to consider ignore items not yet traversed.\n for (const partToDecode of partsToDecode) {\n // once we have traversed the entire ignore list, each decoded part is returned.\n partsToJoin.push(decodePathSegment(partToDecode, decodeIgnore, i + 1))\n }\n\n // and join them back together to form the final decoded path segment with the ignored character in place.\n return partsToJoin.join(char)\n }\n }\n\n // once we have reached the end of the ignore list, we start walking back returning each decoded part.\n // should there be no matching characters, the path segment as a whole will be decoded.\n return decode(part)\n}\n"],"names":["part"],"mappings":"AA8LO,SAAS,KAAQ,KAAe;AACrC,SAAO,IAAI,IAAI,SAAS,CAAC;AAC3B;AAEA,SAAS,WAAW,GAAuB;AACzC,SAAO,OAAO,MAAM;AACtB;AAMO,SAAS,iBACd,SACA,UACS;AACT,MAAI,WAAW,OAAO,GAAG;AACvB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,SAAO;AACT;AAEA,MAAM,SAAS,OAAO,UAAU;AAQzB,SAAS,iBAAoB,MAAW,OAAa;A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AgB,eAAe;AAExC,oBAAY,KAAK,kBAAkB,cAAc,cAAc,IAAI,CAAC,CAAC;AAAA,MACvE;AAGA,aAAO,YAAY,KAAK,IAAI;AAAA,IAC9B;AAAA,EACF;AAIA,SAAO,OAAO,IAAI;AACpB;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import type { RouteIds } from './routeInfo'\nimport type { AnyRouter } from './router'\n\nexport type Awaitable<T> = T | Promise<T>\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\n\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type PickOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = keyof TLeft &\n keyof TRight extends never\n ? TRight\n : Omit<TRight, keyof TLeft & keyof TRight> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n }\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type IsNonEmptyObject<T> = T extends object\n ? keyof T extends never\n ? false\n : true\n : false\n\nexport type Assign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : keyof TLeft & keyof TRight extends never\n ? TLeft & TRight\n : Omit<TLeft, keyof TRight> & TRight\n : never\n : never\n\nexport type IntersectAssign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : TRight & TLeft\n : never\n : never\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive\n ? never\n : TUnion\n\nexport type PartialMergeAllObject<TUnion> =\n ExtractObjects<TUnion> extends infer TObj\n ? [TObj] extends [never]\n ? never\n : {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeAllPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n | undefined\n | null\n\nexport type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type PartialMergeAll<TUnion> =\n | ExtractPrimitives<TUnion>\n | PartialMergeAllObject<TUnion>\n\nexport type Constrain<T, TConstraint, TDefault = TConstraint> =\n | (T extends TConstraint ? T : never)\n | TDefault\n\nexport type ConstrainLiteral<T, TConstraint, TDefault = TConstraint> =\n | (T & TConstraint)\n | TDefault\n\n/**\n * To be added to router types\n */\nexport type UnionToIntersection<T> = (\n T extends any ? (arg: T) => any : never\n) extends (arg: infer T) => any\n ? T\n : never\n\n/**\n * Merges everything in a union into one object.\n * This mapped type is homomorphic which means it preserves stuff! :)\n */\nexport type MergeAllObjects<\n TUnion,\n TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,\n> = [keyof TIntersected] extends [never]\n ? never\n : {\n [TKey in keyof TIntersected]: TUnion extends any\n ? TUnion[TKey & keyof TUnion]\n : never\n }\n\nexport type MergeAll<TUnion> =\n | MergeAllObjects<TUnion>\n | ExtractPrimitives<TUnion>\n\nexport type ValidateJSON<T> = ((...args: Array<any>) => any) extends T\n ? unknown extends T\n ? never\n : 'Function is not serializable'\n : { [K in keyof T]: ValidateJSON<T[K]> }\n\nexport type LooseReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn\n : never\n\nexport type LooseAsyncReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn extends Promise<infer TReturn>\n ? TReturn\n : TReturn\n : never\n\n/**\n * Return the last element of an array.\n * Intended for non-empty arrays used within router internals.\n */\nexport function last<T>(arr: Array<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\n/**\n * Apply a value-or-updater to a previous value.\n * Accepts either a literal value or a function of the previous value.\n */\nexport function functionalUpdate<TPrevious, TResult = TPrevious>(\n updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>,\n previous: TPrevious,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nconst hasOwn = Object.prototype.hasOwnProperty\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (!array && !(isPlainObject(prev) && isPlainObject(next))) return next\n\n const prevItems = array ? prev : getEnumerableOwnKeys(prev)\n if (!prevItems) return next\n const nextItems = array ? next : getEnumerableOwnKeys(next)\n if (!nextItems) return next\n const prevSize = prevItems.length\n const nextSize = nextItems.length\n const copy: any = array ? new Array(nextSize) : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : (nextItems[i] as any)\n const p = prev[key]\n const n = next[key]\n\n if (p === n) {\n copy[key] = p\n if (array ? i < prevSize : hasOwn.call(prev, key)) equalItems++\n continue\n }\n\n if (\n p === null ||\n n === null ||\n typeof p !== 'object' ||\n typeof n !== 'object'\n ) {\n copy[key] = n\n continue\n }\n\n const v = replaceEqualDeep(p, n)\n copy[key] = v\n if (v === p) equalItems++\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n}\n\n/**\n * Equivalent to `Reflect.ownKeys`, but ensures that objects are \"clone-friendly\":\n * will return false if object has any non-enumerable properties.\n */\nfunction getEnumerableOwnKeys(o: object) {\n const keys = []\n const names = Object.getOwnPropertyNames(o)\n for (const name of names) {\n if (!Object.prototype.propertyIsEnumerable.call(o, name)) return false\n keys.push(name)\n }\n const symbols = Object.getOwnPropertySymbols(o)\n for (const symbol of symbols) {\n if (!Object.prototype.propertyIsEnumerable.call(o, symbol)) return false\n keys.push(symbol)\n }\n return keys\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\n/**\n * Check if a value is a \"plain\" array (no extra enumerable keys).\n */\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n/**\n * Perform a deep equality check with options for partial comparison and\n * ignoring `undefined` values. Optimized for router state comparisons.\n */\nexport function deepEqual(\n a: any,\n b: any,\n opts?: { partial?: boolean; ignoreUndefined?: boolean },\n): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false\n for (let i = 0, l = a.length; i < l; i++) {\n if (!deepEqual(a[i], b[i], opts)) return false\n }\n return true\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const ignoreUndefined = opts?.ignoreUndefined ?? true\n\n if (opts?.partial) {\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n if (!deepEqual(a[k], b[k], opts)) return false\n }\n }\n return true\n }\n\n let aCount = 0\n if (!ignoreUndefined) {\n aCount = Object.keys(a).length\n } else {\n for (const k in a) {\n if (a[k] !== undefined) aCount++\n }\n }\n\n let bCount = 0\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n bCount++\n if (bCount > aCount || !deepEqual(a[k], b[k], opts)) return false\n }\n }\n\n return aCount === bCount\n }\n\n return false\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true\n ? T\n : T | undefined\n\nexport type StrictOrFrom<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>\n strict?: TStrict\n }\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n value?: T\n}\n\n/**\n * Create a promise with exposed resolve/reject and status fields.\n * Useful for coordinating async router lifecycle operations.\n */\nexport function createControlledPromise<T>(onResolve?: (value: T) => void) {\n let resolveLoadPromise!: (value: T) => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<T>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = (value: T) => {\n controlledPromise.status = 'resolved'\n controlledPromise.value = value\n resolveLoadPromise(value)\n onResolve?.(value)\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Heuristically detect dynamic import \"module not found\" errors\n * across major browsers for lazy route component handling.\n */\nexport function isModuleNotFoundError(error: any): boolean {\n // chrome: \"Failed to fetch dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // firefox: \"error loading dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // safari: \"Importing a module script failed.\"\n if (typeof error?.message !== 'string') return false\n return (\n error.message.startsWith('Failed to fetch dynamically imported module') ||\n error.message.startsWith('error loading dynamically imported module') ||\n error.message.startsWith('Importing a module script failed')\n )\n}\n\nexport function isPromise<T>(\n value: Promise<Awaited<T>> | T,\n): value is Promise<Awaited<T>> {\n return Boolean(\n value &&\n typeof value === 'object' &&\n typeof (value as Promise<T>).then === 'function',\n )\n}\n\nexport function findLast<T>(\n array: ReadonlyArray<T>,\n predicate: (item: T) => boolean,\n): T | undefined {\n for (let i = array.length - 1; i >= 0; i--) {\n const item = array[i]!\n if (predicate(item)) return item\n }\n return undefined\n}\n\nconst DECODE_IGNORE_LIST = Array.from(\n new Map([\n ['%', '%25'],\n ['\\\\', '%5C'],\n ]).values(),\n)\n\nexport function decodePath(\n part: string,\n decodeIgnore: Array<string> = DECODE_IGNORE_LIST,\n): string {\n function splitAndDecode(\n part: string,\n decodeIgnore: Array<string>,\n startIndex = 0,\n ): string {\n // decode the path / path segment by splitting it into parts defined by the ignore list.\n // once these pieces have been decoded, join them back together to form the final decoded path segment with the ignored character in place.\n // we walk through the ignore list linearly, breaking the segment up into pieces and decoding each piece individually.\n // use index traversal to avoid making unnecessary copies of the array.\n for (let i = startIndex; i < decodeIgnore.length; i++) {\n const char = decodeIgnore[i]!.toUpperCase()\n\n // check if the part includes the current ignore character\n // if it doesn't continue to the next ignore character\n if (part.includes(char)) {\n // split the part into pieces that needs to be checked and decoded\n const partsToDecode = part.split(char)\n const partsToJoin: Array<string> = []\n\n // now check and decode each piece individually taking into consideration the remaining ignored characters.\n // since we are walking through the list linearly, we only need to consider ignore items not yet traversed.\n for (const partToDecode of partsToDecode) {\n // once we have traversed the entire ignore list, each decoded part is returned.\n partsToJoin.push(splitAndDecode(partToDecode, decodeIgnore, i + 1))\n }\n\n // and join them back together to form the final decoded path segment with the ignored character in place.\n return partsToJoin.join(char)\n }\n }\n\n // once we have reached the end of the ignore list, we start walking back returning each decoded part.\n // should there be no matching characters, the path segment as a whole will be decoded.\n try {\n return decodeURI(part)\n } catch {\n // if the decoding fails, try to decode the various parts leaving the malformed tags in place\n return part.replaceAll(/%[0-9A-F]{2}/g, (match) => {\n try {\n return decodeURI(match)\n } catch {\n return match\n }\n })\n }\n }\n\n // if the path segment does not contain any encoded uri components return the path as is\n if (part === '' || !/%[0-9A-Fa-f]{2}/g.test(part)) return part\n\n // ensure all encoded characters are uppercase\n const normalizedPart = part.replaceAll(/%[0-9a-f]{2}/g, (match) =>\n match.toUpperCase(),\n )\n\n return splitAndDecode(normalizedPart, decodeIgnore)\n}\n"],"names":["part","decodeIgnore"],"mappings":"AA8LO,SAAS,KAAQ,KAAe;AACrC,SAAO,IAAI,IAAI,SAAS,CAAC;AAC3B;AAEA,SAAS,WAAW,GAAuB;AACzC,SAAO,OAAO,MAAM;AACtB;AAMO,SAAS,iBACd,SACA,UACS;AACT,MAAI,WAAW,OAAO,GAAG;AACvB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,SAAO;AACT;AAEA,MAAM,SAAS,OAAO,UAAU;AAQzB,SAAS,iBAAoB,MAAW,OAAa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ACpD;"}
|
package/package.json
CHANGED
package/src/RouterProvider.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface CommitLocationOptions {
|
|
|
16
16
|
hashScrollIntoView?: boolean | ScrollIntoViewOptions
|
|
17
17
|
viewTransition?: boolean | ViewTransitionOptions
|
|
18
18
|
/**
|
|
19
|
-
* @deprecated All navigations use
|
|
19
|
+
* @deprecated All navigations use transitions under the hood now
|
|
20
20
|
**/
|
|
21
21
|
startTransition?: boolean
|
|
22
22
|
ignoreBlocker?: boolean
|
package/src/index.ts
CHANGED
package/src/path.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { last } from './utils'
|
|
2
2
|
import type { LRUCache } from './lru-cache'
|
|
3
3
|
import type { MatchLocation } from './RouterProvider'
|
|
4
4
|
import type { AnyPathParams } from './route'
|
|
@@ -358,7 +358,7 @@ function baseParsePathname(pathname: string): ReadonlyArray<Segment> {
|
|
|
358
358
|
// Handle regular pathname segment
|
|
359
359
|
return {
|
|
360
360
|
type: SEGMENT_TYPE_PATHNAME,
|
|
361
|
-
value:
|
|
361
|
+
value: part,
|
|
362
362
|
}
|
|
363
363
|
}),
|
|
364
364
|
)
|
package/src/router.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Store, batch } from '@tanstack/store'
|
|
|
2
2
|
import { createBrowserHistory, parseHref } from '@tanstack/history'
|
|
3
3
|
import {
|
|
4
4
|
createControlledPromise,
|
|
5
|
-
|
|
5
|
+
decodePath,
|
|
6
6
|
deepEqual,
|
|
7
7
|
findLast,
|
|
8
8
|
functionalUpdate,
|
|
@@ -1173,7 +1173,7 @@ export class RouterCore<
|
|
|
1173
1173
|
href: fullPath,
|
|
1174
1174
|
publicHref: href,
|
|
1175
1175
|
url: url.href,
|
|
1176
|
-
pathname,
|
|
1176
|
+
pathname: decodePath(pathname),
|
|
1177
1177
|
searchStr,
|
|
1178
1178
|
search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
|
|
1179
1179
|
hash: hash.split('#').reverse()[0] ?? '',
|
|
@@ -1563,7 +1563,18 @@ export class RouterCore<
|
|
|
1563
1563
|
}
|
|
1564
1564
|
|
|
1565
1565
|
cancelMatches = () => {
|
|
1566
|
-
this.state.
|
|
1566
|
+
const currentPendingMatches = this.state.matches.filter(
|
|
1567
|
+
(match) => match.status === 'pending',
|
|
1568
|
+
)
|
|
1569
|
+
const currentLoadingMatches = this.state.matches.filter(
|
|
1570
|
+
(match) => match.isFetching === 'loader',
|
|
1571
|
+
)
|
|
1572
|
+
const matchesToCancelArray = new Set([
|
|
1573
|
+
...(this.state.pendingMatches ?? []),
|
|
1574
|
+
...currentPendingMatches,
|
|
1575
|
+
...currentLoadingMatches,
|
|
1576
|
+
])
|
|
1577
|
+
matchesToCancelArray.forEach((match) => {
|
|
1567
1578
|
this.cancelMatch(match.id)
|
|
1568
1579
|
})
|
|
1569
1580
|
}
|
|
@@ -1671,7 +1682,7 @@ export class RouterCore<
|
|
|
1671
1682
|
}
|
|
1672
1683
|
}
|
|
1673
1684
|
|
|
1674
|
-
const nextPathname =
|
|
1685
|
+
const nextPathname = decodePath(
|
|
1675
1686
|
interpolatePath({
|
|
1676
1687
|
// Use the original template path for interpolation
|
|
1677
1688
|
// This preserves the original parameter syntax including optional parameters
|
package/src/utils.ts
CHANGED
|
@@ -493,31 +493,53 @@ const DECODE_IGNORE_LIST = Array.from(
|
|
|
493
493
|
new Map([
|
|
494
494
|
['%', '%25'],
|
|
495
495
|
['\\', '%5C'],
|
|
496
|
-
['/', '%2F'],
|
|
497
|
-
[';', '%3B'],
|
|
498
|
-
[':', '%3A'],
|
|
499
|
-
['@', '%40'],
|
|
500
|
-
['&', '%26'],
|
|
501
|
-
['=', '%3D'],
|
|
502
|
-
['+', '%2B'],
|
|
503
|
-
['$', '%24'],
|
|
504
|
-
[',', '%2C'],
|
|
505
496
|
]).values(),
|
|
506
497
|
)
|
|
507
498
|
|
|
508
|
-
export function
|
|
499
|
+
export function decodePath(
|
|
509
500
|
part: string,
|
|
510
501
|
decodeIgnore: Array<string> = DECODE_IGNORE_LIST,
|
|
511
|
-
startIndex = 0,
|
|
512
502
|
): string {
|
|
513
|
-
function
|
|
503
|
+
function splitAndDecode(
|
|
504
|
+
part: string,
|
|
505
|
+
decodeIgnore: Array<string>,
|
|
506
|
+
startIndex = 0,
|
|
507
|
+
): string {
|
|
508
|
+
// decode the path / path segment by splitting it into parts defined by the ignore list.
|
|
509
|
+
// once these pieces have been decoded, join them back together to form the final decoded path segment with the ignored character in place.
|
|
510
|
+
// we walk through the ignore list linearly, breaking the segment up into pieces and decoding each piece individually.
|
|
511
|
+
// use index traversal to avoid making unnecessary copies of the array.
|
|
512
|
+
for (let i = startIndex; i < decodeIgnore.length; i++) {
|
|
513
|
+
const char = decodeIgnore[i]!.toUpperCase()
|
|
514
|
+
|
|
515
|
+
// check if the part includes the current ignore character
|
|
516
|
+
// if it doesn't continue to the next ignore character
|
|
517
|
+
if (part.includes(char)) {
|
|
518
|
+
// split the part into pieces that needs to be checked and decoded
|
|
519
|
+
const partsToDecode = part.split(char)
|
|
520
|
+
const partsToJoin: Array<string> = []
|
|
521
|
+
|
|
522
|
+
// now check and decode each piece individually taking into consideration the remaining ignored characters.
|
|
523
|
+
// since we are walking through the list linearly, we only need to consider ignore items not yet traversed.
|
|
524
|
+
for (const partToDecode of partsToDecode) {
|
|
525
|
+
// once we have traversed the entire ignore list, each decoded part is returned.
|
|
526
|
+
partsToJoin.push(splitAndDecode(partToDecode, decodeIgnore, i + 1))
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// and join them back together to form the final decoded path segment with the ignored character in place.
|
|
530
|
+
return partsToJoin.join(char)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// once we have reached the end of the ignore list, we start walking back returning each decoded part.
|
|
535
|
+
// should there be no matching characters, the path segment as a whole will be decoded.
|
|
514
536
|
try {
|
|
515
|
-
return
|
|
537
|
+
return decodeURI(part)
|
|
516
538
|
} catch {
|
|
517
539
|
// if the decoding fails, try to decode the various parts leaving the malformed tags in place
|
|
518
|
-
return part.replaceAll(/%[0-9A-
|
|
540
|
+
return part.replaceAll(/%[0-9A-F]{2}/g, (match) => {
|
|
519
541
|
try {
|
|
520
|
-
return
|
|
542
|
+
return decodeURI(match)
|
|
521
543
|
} catch {
|
|
522
544
|
return match
|
|
523
545
|
}
|
|
@@ -526,35 +548,12 @@ export function decodePathSegment(
|
|
|
526
548
|
}
|
|
527
549
|
|
|
528
550
|
// if the path segment does not contain any encoded uri components return the path as is
|
|
529
|
-
if (part === '' ||
|
|
530
|
-
|
|
531
|
-
// decode the path / path segment by splitting it into parts defined by the ignore list.
|
|
532
|
-
// once these pieces have been decoded, join them back together to form the final decoded path segment with the ignored character in place.
|
|
533
|
-
// we walk through the ignore list linearly, breaking the segment up into pieces and decoding each piece individually.
|
|
534
|
-
// use index traversal to avoid making unnecessary copies of the array.
|
|
535
|
-
for (let i = startIndex; i < decodeIgnore.length; i++) {
|
|
536
|
-
const char = decodeIgnore[i]
|
|
537
|
-
|
|
538
|
-
// check if the part includes the current ignore character
|
|
539
|
-
// if it doesn't continue to the next ignore character
|
|
540
|
-
if (char && part.includes(char)) {
|
|
541
|
-
// split the part into pieces that needs to be checked and decoded
|
|
542
|
-
const partsToDecode = part.split(char)
|
|
543
|
-
const partsToJoin: Array<string> = []
|
|
544
|
-
|
|
545
|
-
// now check and decode each piece individually taking into consideration the remaining ignored characters.
|
|
546
|
-
// since we are walking through the list linearly, we only need to consider ignore items not yet traversed.
|
|
547
|
-
for (const partToDecode of partsToDecode) {
|
|
548
|
-
// once we have traversed the entire ignore list, each decoded part is returned.
|
|
549
|
-
partsToJoin.push(decodePathSegment(partToDecode, decodeIgnore, i + 1))
|
|
550
|
-
}
|
|
551
|
+
if (part === '' || !/%[0-9A-Fa-f]{2}/g.test(part)) return part
|
|
551
552
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
// ensure all encoded characters are uppercase
|
|
554
|
+
const normalizedPart = part.replaceAll(/%[0-9a-f]{2}/g, (match) =>
|
|
555
|
+
match.toUpperCase(),
|
|
556
|
+
)
|
|
556
557
|
|
|
557
|
-
|
|
558
|
-
// should there be no matching characters, the path segment as a whole will be decoded.
|
|
559
|
-
return decode(part)
|
|
558
|
+
return splitAndDecode(normalizedPart, decodeIgnore)
|
|
560
559
|
}
|