-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Closed
Closed
Copy link
Labels
Description
Version
3.0.3
Reproduction link
Sorry, It is hard to supply a minimal reproduction
Steps to reproduce
Visit http://a.b.c/#/test?d=%25
Vue-router will throw a warning URIError: URI malformed
, and abandon all the query params.
What is expected?
DecodeURI once is enough.
What is actually happening?
DecodeURI twice.
ref:
vue-router/src/history/hash.js
Lines 100 to 106 in 627027f
export function getHash (): string { | |
// We can't use window.location.hash here because it's not | |
// consistent across browsers - Firefox will pre-decode it! | |
const href = window.location.href | |
const index = href.indexOf('#') | |
return index === -1 ? '' : decodeURI(href.slice(index + 1)) | |
} |
Lines 37 to 63 in 627027f
function parseQuery (query: string): Dictionary<string> { | |
const res = {} | |
query = query.trim().replace(/^(\?|#|&)/, '') | |
if (!query) { | |
return res | |
} | |
query.split('&').forEach(param => { | |
const parts = param.replace(/\+/g, ' ').split('=') | |
const key = decode(parts.shift()) | |
const val = parts.length > 0 | |
? decode(parts.join('=')) | |
: null | |
if (res[key] === undefined) { | |
res[key] = val | |
} else if (Array.isArray(res[key])) { | |
res[key].push(val) | |
} else { | |
res[key] = [res[key], val] | |
} | |
}) | |
return res | |
} |
The getHash
method already decoded href, but parseQuery
decode it again. So caused URIError: URI malformed
.
Maybe decoding in getHash
is not necessary.