]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: decode hash when parsing urls (#2061)
authorEduardo San Martin Morote <posva@users.noreply.github.com>
Fri, 1 Dec 2023 19:33:35 +0000 (20:33 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Dec 2023 19:33:35 +0000 (20:33 +0100)
Fix #2060

packages/router/__tests__/urlEncoding.spec.ts
packages/router/src/location.ts

index 82b7fd19272839f3d9a82340437d12663e0d6c84..4102b73bd48a2b0a07dcaf190e9a69e936b30d79 100644 (file)
@@ -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 () => {
@@ -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')
   })
index d2017a3f6f164b738df5739b9e40907a6227a135..ef85d359b13a0b846c6ca63ffa4c9072fa0ddd0d 100644 (file)
@@ -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`}.
@@ -85,7 +86,7 @@ export function parseURL(
     fullPath: path + (searchString && '?') + searchString + hash,
     path,
     query,
-    hash,
+    hash: decode(hash),
   }
 }