Skip to content

Commit 0efb84e

Browse files
committed
fix: decode hash when parsing urls
Fix #2060
1 parent 4555a35 commit 0efb84e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/router/__tests__/urlEncoding.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ describe('URL Encoding', () => {
6868
const router = createRouter()
6969
await router.push('/p/foo')
7070
// one extra time for hash
71-
expect(encoding.decode).toHaveBeenCalledTimes(2)
72-
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'foo')
71+
expect(encoding.decode).toHaveBeenCalledTimes(3)
72+
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo')
7373
})
7474

7575
it('calls decode with a path with repeatable params', async () => {
7676
const router = createRouter()
7777
await router.push('/p/foo/bar')
7878
// one extra time for hash
79-
expect(encoding.decode).toHaveBeenCalledTimes(3)
80-
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'foo', 0, ['foo', 'bar'])
81-
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'bar', 1, ['foo', 'bar'])
79+
expect(encoding.decode).toHaveBeenCalledTimes(4)
80+
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo', 0, ['foo', 'bar'])
81+
expect(encoding.decode).toHaveBeenNthCalledWith(3, 'bar', 1, ['foo', 'bar'])
8282
})
8383

8484
it('decodes values in params', async () => {
@@ -108,7 +108,7 @@ describe('URL Encoding', () => {
108108
const router = createRouter()
109109
await router.push('/?p=foo')
110110
// one extra time for hash
111-
expect(encoding.decode).toHaveBeenCalledTimes(3)
111+
expect(encoding.decode).toHaveBeenCalledTimes(4)
112112
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'p')
113113
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo')
114114
})

packages/router/src/location.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { RouteRecord } from './matcher/types'
88
import { warn } from './warning'
99
import { isArray } from './utils'
10+
import { decode } from './encoding'
1011

1112
/**
1213
* Location object returned by {@link `parseURL`}.
@@ -85,7 +86,7 @@ export function parseURL(
8586
fullPath: path + (searchString && '?') + searchString + hash,
8687
path,
8788
query,
88-
hash,
89+
hash: decode(hash),
8990
}
9091
}
9192

0 commit comments

Comments
 (0)