Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Wildcard in route parameter regexp #2495
Comments
Fishrock123
added the
investigate
label
Jan 12, 2015
|
It's a limitation of the current version of |
dougwilson
self-assigned this
Jan 12, 2015
dougwilson
added 4.x question and removed investigate
labels
Jan 12, 2015
|
I'm going to check if the most recent (non-backwards-compatible) version of |
|
It does. So this should be fixed in 5.0, but as for 4.x, you'll probably have to just use the old syntax :/ |
bevacqua
commented
Jan 12, 2015
|
Thanks for the quick feedback. |
No problem :) Especially for @bevacqua |
charlierudolph
commented
May 7, 2015
|
So is |
|
It's not that we don't want to upgrade As for website issues, please file them at https://github.com/strongloop/expressjs.com |
bevacqua
commented
May 7, 2015
|
For what it's worth, I've been using |
charlierudolph
commented
May 7, 2015
|
I want the upgrade to path-to-regexp for named parameters that can include slashes |
bevacqua
commented
May 7, 2015
|
Don't you need to use |
charlierudolph
commented
May 7, 2015
|
Perfect, thank you @bevacqua |
|
So I looked really hard at this issue for Express 4.x, and it can actually be fixed in |
dougwilson
referenced
this issue
in pillarjs/path-to-regexp
Jun 20, 2015
Closed
fix using asterisk inside param regexp #57
dougwilson
added bug and removed question
labels
Jun 20, 2015
|
Looking through the related PR (pillarjs/path-to-regexp#57), it looks like it would not be possible to fix this in 4.x in a back-compatible way. Is that correct? Or is it just a matter of fixing it in |
|
Sorry, I never updated this issue. Yes, that is correct in that we can't get it fixed in Express 4.x. If you want to take a stab at it, please go ahead! A fresh look never hurts, because it feels like something that should be possible to fix. |
|
So if I understand correctly, to fix the original issue we want to prevent translation of However, we can't do this because we found an example that documents Is that a correct summary? |
|
Yes. Edit: It's possible people also relying on that feature now, so removing (and fixing this issue) would break. I know I've had at least one app in the future abusing the |
|
The only reasonable way to make a back-compatible fix that I can think of would be to add an option you could enable to make Express replace You could push that option up into a patch on I'm happy to have a stab at that change if it's something that we think is desirable. There is a bit of a philosophy question there -- how keen are we on adding options that will be removed next major version to fix bugs that may cause breakage? Otherwise, perhaps we should label this issue with something like "wontfix", "limitation" or "low-priority" to indicate we can't fix it in |
|
The labels are accurate: it's a bug in 4.x, but wont be fixed until 5.0 due to limitations of the implementation we have in 4.x, for better or worse. We keep this issue open for two reasons:
As for the potential solution above, any changes to building a regular expression need to land in our own dependency, otherwise we are not only defeating the purpose of owning our own dependencies, but we are cheating the community out of building complex applications, since they would have to copy and paste into their code instead of updating a dependency. An option, to me, sounds crazy, because if the change would have to be behind a flag, then it sounds like it's not backwards compatible. The way the paths work is an intrinsic property of express, and so a flag to change this behavior at runtime means a community module can no longer know it's routes will just work on a major version of Express, rather they have to instruct users to change this flag or tough luck. |
|
I wasn't thinking we would remove any labels or close the issue, I just wanted to add an extra label so it is easier to see the status/use in a query. Perhaps something like "fix-in-next-release" would capture it? For the potential solution, yes, it was a bit of a stretch idea and certainly far from ideal and, on reflection, the existence of a simple workaround makes it unattractive. I discounted other potential solutions (like special casing It's a shame, because I think it is quite surprising behaviour. |
clakech
commented
Feb 1, 2017
|
Thanks for documenting this in the issue, that helps a lot What is the best workaround: using {0,} or (*) ? both work but which one is a smaller technical debt ? |
|
Using {0,} should work the same with 5.x comes out while (*) will likely change meaning in 5, I believe. |
ttencate
commented
May 15, 2017
|
I spent hours debugging until I found this issue. I understand the reasoning behind leaving the bug in 4.x, but maybe it (and the |
|
Hi @ttencate nothing wrong with documenting! At the bottom of every page on the site, there is a "Edit this page on GitHub." link; just click it and make the edit you think should be good and open a pull request : ) ! Alternatively, you can also file an issue on the website issue tracker. |
ttencate
commented
May 15, 2017
|
Thanks, I somehow overlooked that link :) expressjs/expressjs.com#809 |
bevacqua commentedJan 12, 2015
Route
'/:username([a-z][a-z-]*)'Route
'/:username([a-z][a-z-]*)/:project([a-z][a-z0-9-]*)'URL
/someone/projectExpectation is that the second route should match.
Actual result is the first route matches because the * is considered as all the things rather than "zero or more"
[a-z-].