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

Parameters matching/Update path-to-regexp? #2446

Closed
Lassi opened this issue Nov 21, 2014 · 3 comments
Closed

Parameters matching/Update path-to-regexp? #2446

Lassi opened this issue Nov 21, 2014 · 3 comments
Labels

Comments

@Lassi
Copy link

Lassi commented Nov 21, 2014

Hi,

I've noticed something weird about named parameters in routes. In our app, we use a route similar to this one:

app.get('/concerts/:id*/videos', function (req, res) {});

where the id of a concert is a string formatted like that:

'yyyy/mm/dd/venue/artist'

Now the problem is, if we hit that route:

'/concerts/2014/11/21/venue/artist/videos'

the field req.params.id isn't populated with the value '2014/11/21/venue/artist' as expected, it only contains the value '2014'.

I was wondering if this is the intended behaviour or if this is a bug? I tried to update path-to-regexp from 0.1.3 to its latest version and then everything seemed to work just the way I though it would work.

@jordonias
Copy link
Contributor

This seems relevant, #2173

@dougwilson
Copy link
Contributor

We cannot upgrade since it's not back-wards compatible. It will be upgraded in 5.0 when it comes out, through. If there is a bug and you can get path-to-regexp to publish a new 0.1.x version, we can definitely upgrade to that :)

@dougwilson
Copy link
Contributor

Actually, I'm sorry, I didn't realize the two posts were different people (I thought it was the author confirming it was working with a newer version). So, I re-read the initial post and it's actually working as intended: we only match within path segments (only between the /). You can use your style if you either enumerate out your format in the string ("/concerts/:yyyy/:mm/:dd/:venue/:artist/videos") or you use a regular expression (/\/conerts\/(.+?)\/videos\/?$/).

Another option is that if you want to treat your ID as a single entity in a URL, you need to URL-encode that ID as for proper insertion as a path component: "/contents/" + encodeURIComponent(id) + "/videos".

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

No branches or pull requests

4 participants