From: Eduardo San Martin Morote Date: Fri, 2 Oct 2020 08:10:01 +0000 (+0200) Subject: fix(encoding): keep decoded hash when resolving X-Git-Tag: v4.0.0-beta.13~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a8ffc19b0d2bfc17daec4cb04b96d174c73dd9d;p=thirdparty%2Fvuejs%2Frouter.git fix(encoding): keep decoded hash when resolving --- 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, }) )