Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hq5544 opened this Issue Apr 12, 2019 · 7 comments

Comments

3 participants
@hq5544
Copy link

hq5544 commented Apr 12, 2019

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:

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))
}

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.

@hq5544

This comment has been minimized.

Copy link
Author

hq5544 commented Apr 12, 2019

@posva

This comment has been minimized.

Copy link
Member

posva commented Apr 12, 2019

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

@posva posva added the bug label Apr 12, 2019

@posva posva added this to Long term road (high prio, low complex) in Longterm Apr 12, 2019

@posva posva closed this in #2711 Apr 12, 2019

posva added a commit that referenced this issue Apr 12, 2019

@posva posva moved this from Long term road (high prio, low complex) to Done in Longterm Apr 15, 2019

@jgradzki

This comment has been minimized.

Copy link

jgradzki commented Apr 19, 2019

@posva When this fix will be released?

@hq5544

This comment has been minimized.

Copy link
Author

hq5544 commented Apr 19, 2019

@posva When this fix will be released?

Has released in 3.0.4 81cfe71 .

@jgradzki

This comment has been minimized.

Copy link

jgradzki commented Apr 19, 2019

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

@posva

This comment has been minimized.

Copy link
Member

posva commented Apr 19, 2019

Check #2725

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

@jgradzki

This comment has been minimized.

Copy link

jgradzki commented Apr 19, 2019

Thanks alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.