From 1a8ffc19b0d2bfc17daec4cb04b96d174c73dd9d Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 2 Oct 2020 10:10:01 +0200 Subject: [PATCH] fix(encoding): keep decoded hash when resolving --- __tests__/urlEncoding.spec.ts | 13 +++++++++++++ src/router.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/__tests__/urlEncoding.spec.ts b/__tests__/urlEncoding.spec.ts index e9653af9..699f99d9 100644 --- a/__tests__/urlEncoding.spec.ts +++ b/__tests__/urlEncoding.spec.ts @@ -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: '#%', + }) + }) }) diff --git a/src/router.ts b/src/router.ts index 0527c56f..f5e09412 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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, }) ) -- 2.47.3