Skip to content

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

Merged
merged 4 commits into from
Apr 20, 2017
Merged

Redirects preserve query parameters. #228

merged 4 commits into from
Apr 20, 2017

Conversation

mbleigh
Copy link
Contributor

@mbleigh mbleigh commented Apr 17, 2017

This updates redirects to properly match and redirect when a query string is present, preserving the query string. It explicitly does not:

  1. Allow matching based on query strings
  2. Allow captures to be inserted into query strings

@@ -54,15 +61,15 @@ Redirect.prototype.test = function(url) {

return {
type: this.type,
destination: dest
destination: dest + qs

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)

Copy link
Contributor Author

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 = '';

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.)?

Copy link
Contributor Author

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

@cbraynor cbraynor assigned mbleigh and unassigned cbraynor Apr 19, 2017
Copy link
Contributor Author

@mbleigh mbleigh left a 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.

@@ -54,15 +61,15 @@ Redirect.prototype.test = function(url) {

return {
type: this.type,
destination: dest
destination: dest + qs
Copy link
Contributor Author

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.

@mbleigh mbleigh assigned cbraynor and unassigned mbleigh Apr 20, 2017
Copy link

@cbraynor cbraynor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cbraynor cbraynor assigned mbleigh and unassigned cbraynor Apr 20, 2017
@mbleigh mbleigh merged commit 122ceb5 into master Apr 20, 2017
@mbleigh mbleigh deleted the mb-redirects branch April 20, 2017 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants