Vue-router: Vue-router decodeURI twice cause URL contains encoded % an URIError: URI malformed

Created on 12 Apr 2019  ·  7Comments  ·  Source: vuejs/vue-router

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:
https://github.com/vuejs/vue-router/blob/627027fd4351c1a6fa4926765c805165a56d7818/src/history/hash.js#L100-L106
https://github.com/vuejs/vue-router/blob/627027fd4351c1a6fa4926765c805165a56d7818/src/util/query.js#L37-L63

The getHash method already decoded href, but parseQuery decode it again. So caused URIError: URI malformed.
Maybe decoding in getHash is not necessary.

bug

Most helpful comment

@posva When this fix will be released?

Has released in 3.0.4 https://github.com/vuejs/vue-router/commit/81cfe71296caa5cde21f780ece1910b172b8e5f7 .

All 7 comments

Indeed, we should not decode the search nor the hash in hash mode

@posva When this fix will be released?

@posva When this fix will be released?

Has released in 3.0.4 https://github.com/vuejs/vue-router/commit/81cfe71296caa5cde21f780ece1910b172b8e5f7 .

Thanks for fast response, i guess i have similar but diffrent issue

URIError: URI malformed at decodeURIComponent (<anonymous>) at matchRoute (<deleted>/node_modules/vue-router/dist/vue-router.common.js:1530:42)

```
for (var i = 1, len = m.length; i < len; ++i) {
var key = regex.keys[i - 1];
console.log(m[i]);
var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i];
if (key) {
// Fix #1994: using * with props: true generates a param named 0
params[key.name || 'pathMatch'] = val;
}
}
````

value that triggers error: product/100-%-polipropylen-–-bcf

Check #2725

BTW % is not a valid character in a url (per spec). You have to use the escaped version %25

Thanks alot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shinygang picture shinygang  ·  3Comments

posva picture posva  ·  3Comments

thomas-alrek picture thomas-alrek  ·  3Comments

yyx990803 picture yyx990803  ·  3Comments

gil0mendes picture gil0mendes  ·  3Comments