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

Doesn't correctly escape slashes #29

Open
carmandrew opened this issue Jun 2, 2017 · 3 comments
Open

Doesn't correctly escape slashes #29

carmandrew opened this issue Jun 2, 2017 · 3 comments

Comments

@carmandrew
Copy link

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

@carmandrew
Copy link
Author

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)

@carmandrew carmandrew changed the title Doesn't correctly escape characters Doesn't correctly escape slashes Jun 3, 2017
@AbhilashSrivastava
Copy link

?? Any help on this ??

@hiagolcm
Copy link

I recommend using this lib while this problem is not solved

https://github.com/pillarjs/path-to-regexp#compile-reverse-path-to-regexp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants