]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(encoding): keep decoded hash when resolving
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 2 Oct 2020 08:10:01 +0000 (10:10 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 2 Oct 2020 08:10:01 +0000 (10:10 +0200)
__tests__/urlEncoding.spec.ts
src/router.ts

index e9653af9a7201ac6dfc4018b8112c66a69ba7413..699f99d9f1867d08c3cbc59d543ac5b057b93dcf 100644 (file)
@@ -128,4 +128,17 @@ describe('URL Encoding', () => {
       query: { p: '%' },
     })
   })
+
+  it('keeps decoded values in hash', async () => {
+    // @ts-ignore: override to make the difference
+    encoding.decode = () => 'd'
+    // @ts-ignore
+    encoding.encodeHash = () => '#e'
+    const router = createRouter()
+    await router.push({ name: 'home', hash: '#%' })
+    expect(router.currentRoute.value).toMatchObject({
+      fullPath: '/#e',
+      hash: '#%',
+    })
+  })
 })
index 0527c56f7f97b7ff2af070072819b62511aee070..f5e09412af45bbcf748f8fbea0291c7894781cc0 100644 (file)
@@ -455,7 +455,7 @@ export function createRouter(options: RouterOptions): Router {
     }
 
     let matchedRoute = matcher.resolve(matcherLocation, currentLocation)
-    const hash = encodeHash(rawLocation.hash || '')
+    const hash = rawLocation.hash || ''
 
     if (__DEV__ && hash && !hash.startsWith('#')) {
       warn(
@@ -470,7 +470,7 @@ export function createRouter(options: RouterOptions): Router {
     const fullPath = stringifyURL(
       stringifyQuery,
       assign({}, rawLocation, {
-        hash,
+        hash: encodeHash(hash),
         path: matchedRoute.path,
       })
     )