Percent signs in request results in "URI malformed" error
silverwind opened this issue · 2 comments
silverwind commented
Example:
(require('rlite-router')(() => console.log('404'), {
'/foo': () => console.log('foo'),
}))('/a%b');
Results in
URIError: URI malformed
at decodeURIComponent (<anonymous>)
at recurseUrl (node_modules/rlite-router/rlite.js:65:19)
at recurseUrl (node_modules/rlite-router/rlite.js:67:14)
at lookup (node_modules/rlite-router/rlite.js:99:42)
at run (node_modules/rlite-router/rlite.js:119:20)
Do I need to pass URL-encoded values, or is it a possible bug?
chrisdavies commented
Yes, rlite decodes the URL components so that unescaped values can be passed to the handlers. (e.g. the handlers would get "Chris Davies" instead of "Chris%20Davies". If you pass an invalid URL, it will currently throw an exception (that's the behavior of decodeURIComponent
). So, your URL would work if you passed /a%25b
instead.
Generally speaking, browsers do this for you, so the only problem is when you manually pass in an invalid URL as in your example.
silverwind commented
Okay, I'll just replace %
with %25
before passing it to rlite. Hopefully this is the only such case.