-
Notifications
You must be signed in to change notification settings - Fork 983
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
fix(router): handle non-trailing slashes correctly #1478
fix(router): handle non-trailing slashes correctly #1478
Conversation
5c517b2
to
54f8430
Compare
765769e
to
0c3862d
Compare
test/router.test.js
Outdated
t.ok(trailing.path.test('/trailing')); | ||
|
||
var noTrailing = server.router.routes.GET[1]; | ||
t.ok(noTrailing.path.test('/no-trailing')); | ||
t.ok(noTrailing.path.test('//no-trailing//')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I have enough context to understand why this change is necessary. Why did we change an existing test as opposed to adding a separate test for a single leading /
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original test case is not related to the code what it tests. This test should focus to double no-trailing slashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sry, I mean it should focus to slashes at the end of the path :P
@hekike thanks for taking this on! I think you're right, the behavior should be to not remove double slashes by default - that should be taken care of by the dedupeSlashes plugin. This is going to be a breaking change, perhaps we can slide this in before we cut 6.x @retrohacker? |
Apologize I didn't explain very well the context of this pr.
I believe what @DonutEspresso proposes is a one step further and wouldn't allow, more than one slash at the end neither. The new behavior after this proposal would be:
|
Thanks for tackling this @hekike! I'm 👍 on leaving the path exactly as is, and allowing the user to specify the dedupe behavior through a plugin. My main motivation is that we should do as little "magic" as possible, and changing paths before they get to the user seems like magic. I think our plugin logic should behave like |
So, tl;dr, I propose:
|
As for holding v6, I'd suggest we go ahead and ship. We've been in a state of perpetually staged breaking changes before (as @yunong pointed out yesterday) and it wasn't a great place to be. Instead, I'd suggest we create a new branch called
|
BREAKING CHANGE: use server.pre(restify.plugins.pre.dedupeSlashes()) to deal with double slashes
0c3862d
to
d83ef0f
Compare
@retrohacker I removed the double slash merging magic from the router, see my latest commit. I also refactored the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM 👍
lib/router.js
Outdated
@@ -103,7 +103,7 @@ function compileURL(options) { | |||
return (false); | |||
} | |||
|
|||
pattern += '\\/+'; | |||
pattern += '\\/{1}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this quantifier is unnecessary
@@ -134,7 +134,7 @@ function compileURL(options) { | |||
} | |||
|
|||
if (!options.strict) { | |||
pattern += '[\\/]*'; | |||
pattern += '[\\/]?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this list is unnecessary
This shouldn't merge into |
@retrohacker I've no permission to create a |
Closed by the favor of #1512 |
Issues
Closes:
#1464
Non-trailing slash leads to incorrect routing match (and parameter parsing).
Changes
Fix router regexp matching with non-trailing slash(es)