-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix trailing redirection with query parameters #936
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 trailing redirection with query parameters #936
Conversation
When the request URI matches a route that need a trailing slash, or has an extra trailing slash, the redirect URI is not generated correctly. This change adds or removes a trailing slash to the path part of the URI, instead of the full URI, preserving query parameters during redirection. Signed-off-by: David Calavera <david.calavera@gmail.com>
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.
str::replace
replaces all matches of a pattern, so /foo?bar=/foo
would get rewritten to /foo/?bar=/foo/
. Please use something like .find('?')
+ .insert(idx, '/')
instead.
There are also methods to take apart the path and query. Can't quite put it back together as easily but I think that's safer to use. We do that already in |
Extract parts from Uri and recreate it, so it doesn't bump into corner cases with string manipulation. Signed-off-by: David Calavera <david.calavera@gmail.com>
@jplatte, @davidpdrsn I've updated it to make it safer |
Signed-off-by: David Calavera <david.calavera@gmail.com>
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.
Thanks for noticing this! I had one minor comment.
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Updated |
Motivation
When the request URI matches a route that needs a trailing slash, or has an extra trailing slash, the redirect URI is not generated correctly.
This change adds or removes a trailing slash to the path part of the URI, instead of the full URI, preserving query parameters during redirection.