route-parser
route-parser copied to clipboard
Doesn't correctly escape slashes
const a = new RouteParser('/foo/:bar')
a.reverse({bar: 'hi/test'})
// Returns "/foo/hi/test"
a.reverse({bar: 'hi test'})
// Returns "/foo/hi%20test"
Either the first should return "/foo/hi%2ftest"
(by calling EncodeURIComponent on each param) or the second should return "/foo/hi test"
(so that the caller can encode the components). But with the current behavior, there is no way to encode a string like "foo hi/test" because there is no way to encode both the slash without double encoding the space (ie. into "%2520")
Failing test case:
it('correctly escapes slashes when reversing routes', function () {
var route = RouteParser('/things/:foo');
assert.equal(route.reverse({ foo: 'foo/bar baz' }), '/things/foo%2fbar%20baz');
});
Currently, this returns:
1) Route reverse correctly escapes slashes when reversing routes:
AssertionError: expected '/things/foo/bar%20baz' to equal '/things/foo%2fbar%20baz'
at Context.<anonymous> (test/test.js:185:14)
?? Any help on this ??
I recommend using this lib while this problem is not solved
https://github.com/pillarjs/path-to-regexp#compile-reverse-path-to-regexp