-
Notifications
You must be signed in to change notification settings - Fork 84
Redirects preserve query parameters. #228
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
Conversation
lib/middleware/redirects.js
Outdated
@@ -54,15 +61,15 @@ Redirect.prototype.test = function(url) { | |||
|
|||
return { | |||
type: this.type, | |||
destination: dest | |||
destination: dest + qs |
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 it's possible for destinations to contain a query string - do we want to check and possibly merge query strings (overwriting? adding? if we get a collision)
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.
Let's keep it simple -- I'm now appending them, including a dup if there's a dup between the supplied qs and the destination qs.
@@ -34,6 +34,13 @@ var Redirect = function(source, destination, type) { | |||
}; | |||
|
|||
Redirect.prototype.test = function(url) { | |||
var qs = ''; |
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.
Should we explicitly remove the query string in all places we match (rewrites, headers etc.)?
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.
We don't need to - it's pathToRegexp
that falls apart with a query string, everywhere else we use minimatch
which handles these things just fine:
minimatch('/foo/bar?baz=qux', '/foo/*'); // => true
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.
Addressed comments and added a test for destination with query string.
lib/middleware/redirects.js
Outdated
@@ -54,15 +61,15 @@ Redirect.prototype.test = function(url) { | |||
|
|||
return { | |||
type: this.type, | |||
destination: dest | |||
destination: dest + qs |
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.
Let's keep it simple -- I'm now appending them, including a dup if there's a dup between the supplied qs and the destination qs.
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.
LGTM
This updates redirects to properly match and redirect when a query string is present, preserving the query string. It explicitly does not: