-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Fix query object state mutation during pagination #11244
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 query object state mutation during pagination #11244
Conversation
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.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.
Pull Request Overview
This PR fixes mutation of the original query slice during pagination and adds tests to ensure quoted multi-word keywords are handled correctly across search endpoints and URL generation.
- Refactor formatKeywords to return a new slice instead of mutating the input
- Add pagination test cases for multi-word queries in code, commits, repositories, and issues
- Add a URL-encoding test for quoted multi-word keywords
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
pkg/search/query.go | Changed formatKeywords to allocate a new result slice rather than mutating the input |
pkg/search/searcher_test.go | Added tests for paginating with quoted multi-word queries and URL encoding |
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.
Looks good to me!
func formatKeywords(ks []string) []string { | ||
result := make([]string, len(ks)) | ||
for i, k := range ks { | ||
before, after, found := strings.Cut(k, ":") | ||
if !found { | ||
ks[i] = quote(k) | ||
result[i] = quote(k) | ||
} else { | ||
ks[i] = fmt.Sprintf("%s:%s", before, quote(after)) | ||
result[i] = fmt.Sprintf("%s:%s", before, quote(after)) | ||
} | ||
} | ||
return ks | ||
return result |
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.
note: just to clarify, this function had a side effect of modifying Query.Keywords
field which is used else where. Refactoring this logic to not modify the input avoids the redundant formatting issue.
Fixes #11228
This PR fixes the issue with mutating original query object during pagination API calls. Test cases were added to assert the expected behaviour.
Verifying A/C
Given I have a query that contains a whitespace character, and my query will result in several pages of pagination
When I run the
gh search
command (for any subcommand)Then my query should complete without error
I found a simple use case to verify the expected behaviour. It's looking for the abundant Lorem Ipsum phrase with a grouping of words that forces
gh
to quote them:This works fine with the changes in this PR, but if we run it with the latest
gh
(or on thetrunk
branch) we'll get the following error: