-
Notifications
You must be signed in to change notification settings - Fork 141
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
Broken parsing of route with multiple params within the same couple of slash #314
Comments
@ivan-tymoshenko could you take a look? |
Hi, tried routing with simple app: const router = require('find-my-way')()
router.on('GET', '/example/:near/:lat-:lng/', (req, _, params) => console.log(req, params))
router.lookup({ method: 'GET', url: '/example/oslo/16-8/' }); Params are handled corectly both in v5.3.0 and v5.4.0:
But the problem is that incorrect parsing causes collisions: const router = require('find-my-way')()
router.on('GET', '/example/:near/:lat-:lng', () => {})
router.on('GET', '/example/:near/:coords', () => {})
console.log(router.prettyPrint())
|
@ivan-tymoshenko Did you have a chance to take a look at this? |
Sorry for the long delay. I checked what is going on.
There was a major change made in #237, where we agreed that we can't treat a multiparametric node (
Static parts of these two nodes a the same and this is one of the caveats. What we can potentially do in this case. We can allow users to have parametric and regex/multiparametric nodes in case there would be only one regex node. In this case, we know that the regex node has higher priority than the regular one. @petrsloup @kudlav Sorry for having breaking changes. That PR changed the way we work with multi-parametrical nodes and shouldn't break anything. I can't really fix it, I can try to add a new feature and if it doesn't make any perf downgrade it will resolve your case. |
After second thought I think it's impossible to implement in general. If we allow register parametric and regex nodes for the same static parts, we might have some priority issues. Example:
It's unclear which handler should be executed if I pass a path like that |
Hi Ivan, |
Fixed #320 |
Hi, tried v7.5.0. const router = require('find-my-way')()
router.on('GET', '/example/:near/:lat-:lng/', () => {})
console.log(router.prettyPrint()) output:
the following script which was working in v5.3.0 is still broken const router = require('find-my-way')()
router.on('GET', '/example/:y(^\\d+).:format(^\\w+)', () => {})
router.on('GET', '/example/:y(^\\d+)', () => {})
console.log(router.prettyPrint()) |
Broken parsing of route with multiple params within the same couple of slash
Last working version
5.3.0
Stopped working in version
5.4.0 (also broken in the latest 7.4.0)
Node.js version
16.19.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.1 LTS
💥 Regression Report
When the route contains multiple parameter within the same couple of slash ("/"), the parameter in previous slash part is dropped.
(Affects both when multiple params are RegExp and non RegExp parameters.)
See the following example file:
Output:
└── /example/:near/:lat-:lng/ (GET)
└── /example/:lat/:lng/ (GET)
You can see that
:near
param is dropped in v 5.4.0.It's caused by more than one parameter withing the same couple of slash ("/").
Because this works (added a slash between lat and lng):
Output same in v5.3.0 and v5.4.0:
└── /example/:near/:lat/:lng/ (GET)
Expected output
same as in v5.3.0
original Issue: fastify/fastify#4506
The text was updated successfully, but these errors were encountered: