Skip to content

Commit 878da35

Browse files
committed
rename function
1 parent c5528e4 commit 878da35

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

‎packages/router-core/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export {
278278
deepEqual,
279279
createControlledPromise,
280280
isModuleNotFoundError,
281-
decodePathSegment,
281+
decodePath,
282282
} from './utils'
283283
export type {
284284
NoInfer,

‎packages/router-core/src/router.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Store, batch } from '@tanstack/store'
22
import { createBrowserHistory, parseHref } from '@tanstack/history'
33
import {
44
createControlledPromise,
5-
decodePathSegment,
5+
decodePath,
66
deepEqual,
77
findLast,
88
functionalUpdate,
@@ -1173,7 +1173,7 @@ export class RouterCore<
11731173
href: fullPath,
11741174
publicHref: href,
11751175
url: url.href,
1176-
pathname: decodePathSegment(pathname),
1176+
pathname: decodePath(pathname),
11771177
searchStr,
11781178
search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
11791179
hash: hash.split('#').reverse()[0] ?? '',
@@ -1671,7 +1671,7 @@ export class RouterCore<
16711671
}
16721672
}
16731673

1674-
const nextPathname = decodePathSegment(
1674+
const nextPathname = decodePath(
16751675
interpolatePath({
16761676
// Use the original template path for interpolation
16771677
// This preserves the original parameter syntax including optional parameters

‎packages/router-core/src/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ const DECODE_IGNORE_LIST = Array.from(
496496
]).values(),
497497
)
498498

499-
export function decodePathSegment(
499+
export function decodePath(
500500
part: string,
501501
decodeIgnore: Array<string> = DECODE_IGNORE_LIST,
502502
): string {

‎packages/router-core/tests/utils.test.ts‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, describe, expect, it } from 'vitest'
22
import {
3-
decodePathSegment,
3+
decodePath,
44
deepEqual,
55
isPlainArray,
66
replaceEqualDeep,
@@ -498,14 +498,14 @@ describe('deepEqual', () => {
498498
})
499499
})
500500

501-
describe('decodePathSegment', () => {
501+
describe('decodePath', () => {
502502
it('should decode a path segment with no ignored items existing', () => {
503503
const itemsToCheck = ['%25', '%5C']
504504
const stringToCheck =
505505
'https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'
506506
const expectedResult = 'https://mozilla.org/?x=шеллы'
507507

508-
const result = decodePathSegment(stringToCheck, itemsToCheck)
508+
const result = decodePath(stringToCheck, itemsToCheck)
509509

510510
expect(result).toBe(expectedResult)
511511
})
@@ -516,7 +516,7 @@ describe('decodePathSegment', () => {
516516
'https://mozilla.org/?x=%25%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
517517
const expectedResult = 'https://mozilla.org/?x=%25ше\\ллы'
518518

519-
const result = decodePathSegment(stringToCheck, itemsToCheck)
519+
const result = decodePath(stringToCheck, itemsToCheck)
520520

521521
expect(result).toBe(expectedResult)
522522
})
@@ -527,14 +527,14 @@ describe('decodePathSegment', () => {
527527
'https://mozilla.org/?x=%25%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'
528528
let expectedResult = 'https://mozilla.org/?x=%25шеллы'
529529

530-
let result = decodePathSegment(stringToCheck, itemsToCheck)
530+
let result = decodePath(stringToCheck, itemsToCheck)
531531

532532
expect(result).toBe(expectedResult)
533533

534534
stringToCheck = 'https://mozilla.org/?x=%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
535535
expectedResult = 'https://mozilla.org/?x=ше%5Cллы'
536536

537-
result = decodePathSegment(stringToCheck, itemsToCheck)
537+
result = decodePath(stringToCheck, itemsToCheck)
538538

539539
expect(result).toBe(expectedResult)
540540
})
@@ -545,14 +545,14 @@ describe('decodePathSegment', () => {
545545
'https://mozilla.org/?x=%5C%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'
546546
let expectedResult = 'https://mozilla.org/?x=%5Cшеллы'
547547

548-
let result = decodePathSegment(stringToCheck, itemsToCheck)
548+
let result = decodePath(stringToCheck, itemsToCheck)
549549

550550
expect(result).toBe(expectedResult)
551551

552552
stringToCheck = 'https://mozilla.org/?x=%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
553553
expectedResult = 'https://mozilla.org/?x=ше%5Cллы'
554554

555-
result = decodePathSegment(stringToCheck, itemsToCheck)
555+
result = decodePath(stringToCheck, itemsToCheck)
556556

557557
expect(result).toBe(expectedResult)
558558
})
@@ -563,7 +563,7 @@ describe('decodePathSegment', () => {
563563
'https://mozilla.org/?x=%25%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
564564
const expectedResult = 'https://mozilla.org/?x=%25ше%5Cллы'
565565

566-
const result = decodePathSegment(stringToCheck, itemsToCheck)
566+
const result = decodePath(stringToCheck, itemsToCheck)
567567

568568
expect(result).toBe(expectedResult)
569569
})
@@ -573,42 +573,42 @@ describe('decodePathSegment', () => {
573573
'https://mozilla.org/?x=%25%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B%2F'
574574
const expectedResult = 'https://mozilla.org/?x=%25ше%5Cллы%2F'
575575

576-
const result = decodePathSegment(stringToCheck)
576+
const result = decodePath(stringToCheck)
577577

578578
expect(result).toBe(expectedResult)
579579
})
580580

581581
it('should handle malformed percent-encodings gracefully', () => {
582582
const stringToCheck = 'path%ZZ%D1%88test%5C%C3%A9'
583583
// Malformed sequences should remain as-is, valid ones decoded
584-
const result = decodePathSegment(stringToCheck)
584+
const result = decodePath(stringToCheck)
585585
expect(result).toBe(`path%ZZ%D1%88test%5Cé`)
586586
})
587587

588588
it('should return empty string unchanged', () => {
589-
expect(decodePathSegment('')).toBe('')
589+
expect(decodePath('')).toBe('')
590590
})
591591

592592
it('should return strings without encoding unchanged', () => {
593593
const stringToCheck = 'plain-text-path'
594-
expect(decodePathSegment(stringToCheck)).toBe(stringToCheck)
594+
expect(decodePath(stringToCheck)).toBe(stringToCheck)
595595
})
596596

597597
it('should handle consecutive ignored characters', () => {
598598
const stringToCheck = 'test%25%25end'
599599
const expectedResult = 'test%25%25end'
600-
expect(decodePathSegment(stringToCheck)).toBe(expectedResult)
600+
expect(decodePath(stringToCheck)).toBe(expectedResult)
601601
})
602602

603603
it('should handle multiple ignored items of the same type with varying case', () => {
604604
const stringToCheck = '/params-ps/named/foo%2Fabc/c%2Fh'
605605
const expectedResult = '/params-ps/named/foo%2Fabc/c%2Fh'
606-
expect(decodePathSegment(stringToCheck)).toBe(expectedResult)
606+
expect(decodePath(stringToCheck)).toBe(expectedResult)
607607

608608
const stringToCheckWithLowerCase = '/params-ps/named/foo%2Fabc/c%5C%2f%5cAh'
609609
const expectedResultWithLowerCase =
610610
'/params-ps/named/foo%2Fabc/c%5C%2F%5CAh'
611-
expect(decodePathSegment(stringToCheckWithLowerCase)).toBe(
611+
expect(decodePath(stringToCheckWithLowerCase)).toBe(
612612
expectedResultWithLowerCase,
613613
)
614614
})

0 commit comments

Comments
 (0)