Skip to content

Commit 07dbfea

Browse files
committed
simplify more
1 parent 335ba30 commit 07dbfea

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,16 @@ function decodeSegment(segment: string): string {
505505
}
506506

507507
export function decodePath(path: string, decodeIgnore?: Array<string>): string {
508+
if (!path) return path
508509
const re = decodeIgnore
509510
? new RegExp(`${decodeIgnore.join('|')}`, 'gi')
510511
: /%25|%5C/gi
511512
let cursor = 0
512513
let result = ''
513514
let match
514515
while (null !== (match = re.exec(path))) {
515-
const i = match.index
516-
const chunk = match[0]
517-
result += decodeSegment(path.slice(cursor, i)) + chunk
518-
cursor = i + chunk.length
516+
result += decodeSegment(path.slice(cursor, match.index)) + match[0]
517+
cursor = re.lastIndex
519518
}
520-
return result + decodeSegment(path.slice(cursor))
519+
return result + decodeSegment(cursor ? path.slice(cursor) : path)
521520
}

0 commit comments

Comments
 (0)