fix(gstr): preserve repeated query parameters in Parse (fix #4751) - #4817
Open
waterWang wants to merge 1 commit into
Open
fix(gstr): preserve repeated query parameters in Parse (fix #4751)#4817waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
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.
fix(gstr): preserve repeated query parameters in Parse (fix #4751)
What
Fix
gstr.Parseto preserve repeated query parameters when a plain key appears multiple times. Previously,?name=a&name=bwould only keep the last value ("b"), now it correctly produces["a", "b"].Why
When a GoFrame request handler receives a URL like
?names=a&names=band the target struct field is[]string,r.Parse(&req)should bind both values. Thegstr.Parsefunction'sbuildmethod was overwriting the existing value instead of collecting all values into a slice.How
Changed the
buildfunction'slength == 1branch to check if the key already exists in the result map. If it does, both the existing and new values are converted to a[]anyslice and appended. This is consistent with the existing[]notation behavior (v[]=a&v[]=b→[a b]), but without requiring explicit slice notation.Documentation updates
The
Parsefunction's doc comment is updated to reflect the new behavior:v=m&v=n -> map[v:[m n]](wasmap[v:n])Testing
Before:
After:
Fixes #4751