From: Eduardo San Martin Morote Date: Fri, 27 May 2022 22:44:11 +0000 (+0200) Subject: fix: correctly resolve hash including a search X-Git-Tag: v4.1.0~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=136bf2146071d017702c3989f08d26dc5cbe5292;p=thirdparty%2Fvuejs%2Frouter.git fix: correctly resolve hash including a search Fix #1422 --- diff --git a/__tests__/location.spec.ts b/__tests__/location.spec.ts index 4846f87a..6e1ea82c 100644 --- a/__tests__/location.spec.ts +++ b/__tests__/location.spec.ts @@ -133,6 +133,15 @@ describe('parseURL', () => { }) }) + it('parses ? after the hash', () => { + expect(parseURL('/foo/#?a=one')).toEqual({ + fullPath: '/foo/#?a=one', + path: '/foo/', + hash: '#?a=one', + query: {}, + }) + }) + it('calls parseQuery', () => { const parseQuery = jest.fn() originalParseURL(parseQuery, '/?é=é&é=a') diff --git a/src/location.ts b/src/location.ts index c6e6f498..18ca5339 100644 --- a/src/location.ts +++ b/src/location.ts @@ -53,8 +53,13 @@ export function parseURL( hash = '' // Could use URL and URLSearchParams but IE 11 doesn't support it - const searchPos = location.indexOf('?') - const hashPos = location.indexOf('#', searchPos > -1 ? searchPos : 0) + // TODO: move to new URL() + const hashPos = location.indexOf('#') + let searchPos = location.indexOf('?') + // the hash appears before the search, so it's not part of the search string + if (hashPos < searchPos && hashPos >= 0) { + searchPos = -1 + } if (searchPos > -1) { path = location.slice(0, searchPos)