Skip to content

Commit

Permalink
fix: decode hash when parsing urls
Browse files Browse the repository at this point in the history
Fix #2060
  • Loading branch information
posva committed Dec 1, 2023
1 parent 4555a35 commit 0efb84e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/router/__tests__/urlEncoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ describe('URL Encoding', () => {
const router = createRouter()
await router.push('/p/foo')
// one extra time for hash
expect(encoding.decode).toHaveBeenCalledTimes(2)
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'foo')
expect(encoding.decode).toHaveBeenCalledTimes(3)
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo')
})

it('calls decode with a path with repeatable params', async () => {
const router = createRouter()
await router.push('/p/foo/bar')
// one extra time for hash
expect(encoding.decode).toHaveBeenCalledTimes(3)
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'foo', 0, ['foo', 'bar'])
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'bar', 1, ['foo', 'bar'])
expect(encoding.decode).toHaveBeenCalledTimes(4)
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo', 0, ['foo', 'bar'])
expect(encoding.decode).toHaveBeenNthCalledWith(3, 'bar', 1, ['foo', 'bar'])
})

it('decodes values in params', async () => {
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('URL Encoding', () => {
const router = createRouter()
await router.push('/?p=foo')
// one extra time for hash
expect(encoding.decode).toHaveBeenCalledTimes(3)
expect(encoding.decode).toHaveBeenCalledTimes(4)
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'p')
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo')
})
Expand Down
3 changes: 2 additions & 1 deletion packages/router/src/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { RouteRecord } from './matcher/types'
import { warn } from './warning'
import { isArray } from './utils'
import { decode } from './encoding'

/**
* Location object returned by {@link `parseURL`}.
Expand Down Expand Up @@ -85,7 +86,7 @@ export function parseURL(
fullPath: path + (searchString && '?') + searchString + hash,
path,
query,
hash,
hash: decode(hash),
}
}

Expand Down

0 comments on commit 0efb84e

Please sign in to comment.