]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: correctly resolve hash including a search
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 27 May 2022 22:44:11 +0000 (00:44 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Jun 2022 07:59:00 +0000 (09:59 +0200)
Fix #1422

__tests__/location.spec.ts
src/location.ts

index 4846f87a17c830d126a3e9b9f4d4482d5050f0d1..6e1ea82caceb9e33efb21240b41335598d77b123 100644 (file)
@@ -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')
index c6e6f49867f08959b74581c6f987e7f4e05c8e0b..18ca533957a5ea19b5e0c45bce1e037a065bfc18 100644 (file)
@@ -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)