Repository navigation
T-137: fix(redirect): merge query string with the one already in the url - #160
Open
fleet-panda[bot] wants to merge 2 commits into
Open
fleet-panda[bot] wants to merge 2 commits into
fleet-panda[bot] wants to merge 2 commits into
Conversation
sendResponse always built "${url}?${qs}", so withQs() or forwarded
query strings gave "/users?page=2?success=1" when the target already had
a query string, and "/users#list?success=1" when it had a fragment.
Join with "&" when the url already has a "?", and keep the fragment at
the end.
Fixes #157
Parse the query string of the url and assign the new values on it, as
back() does, so withQs({ page: 3 }).toPath('/users?page=2') redirects
to /users?page=3 and not to /users?page=2&page=3.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #158 by @bardrop
Fixes #157
Goal
A redirect to a URL that already has a query string adds a second
?.toIntended()of@adonisjs/sessionpasses such a URL totoPath(), because the session savesrequest.url(true)as the intended URL. For example,withQs({ welcome: 1 }).toIntended('/dashboard')after a login from/dashboard?tab=billingredirects to/dashboard?tab=billing?welcome=1.This pull request keeps the commit of #158, and adds one commit on top of it.
#sendResponsenow parses the query string of the URL with the configuredqsparser, asback()does, and assigns the new values on it. A value ofwithQs(), or of the forwarded query string, replaces the same key of the URL. The fragment stays at the end.Deployment requirements
@adonisjs/http-serveras a patch after the merge.Acceptance criteria
withQs({ success: 1 }).toPath('/users?page=2')redirects to/users?page=2&success=1. Test:append query string to a url that already has one. Passes.withQs({ success: 1 }).toPath('/users?page=2#list')redirects to/users?page=2&success=1#list, andwithQs({ success: 1 }).toPath('/users#list')redirects to/users?success=1#list. Tests:add query string before the url fragment,add query string before the fragment of a url without one. Pass.withQs({ page: 3 }).toPath('/users?page=2')redirects to/users?page=3. Tests:replace the keys of the url query string with the custom query string,replace the keys of the url query string with the forwarded query string. Pass. Both fail on the commit of fix(redirect): merge query string with the one already in the url #158.withQs({ success: 1 }).toPath('https://example.com/users?page=2')giveshttps://example.com/users?page=2&success=1. Test:keep the host of an absolute url when merging the query string. Passes.keep the url as it is when there is no query string to add(/users?page=2&page=3#liststays the same). Passes.npm run lint,npm run typecheckandnpm run quick:test(680 tests) pass.Context changes
None.
Discovered work
None.