-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Use url.QueryEscape instead of url.PathEscape to escape query string #1125
Use url.QueryEscape instead of url.PathEscape to escape query string #1125
Conversation
Thank you, @pankona. Can you please take a look at #966 and #963 for me? import (
qs "github.com/google/go-querystring/query"
)
...
params, err := qs.Values(opt)
if err != nil {
return nil, err
}
params.Set("q", parameters.Query)
if parameters.RepositoryID != nil {
params.Set("repository_id", strconv.FormatInt(*parameters.RepositoryID, 10))
}
u := fmt.Sprintf("search/%s?%s", searchType, params.Encode()) and I'm wondering if the correct fix is to make the changes in the upstream Thoughts? |
Thank you, @pankona! I'll have to take time and look at this tonight... gotta run... but in a nutshell, was #966 just broken? I'm curious how this current PR differs from the original, but don't have time right now to look... I just know there was a problem in #963 that needed fixing and hope that this addresses that issue as well. |
I've checked snippet on #963 (as follows) rs, _, err := client.Search.Repositories(context.Background(),
"language:golang+stars:>=200+pushed:>=2018-01-01",
&github.SearchOptions{Sort: "stars", Order: "desc",
ListOptions: github.ListOptions{Page: 2, PerPage: 100}}) This query string includes "+" (instead of white space). I think this is NOT acceptable query string.
|
...although it worked when using But are you saying here that the original code was correct? |
Yes. I think original code was correct. In my understanding, escaping of query string is responsibility of go-github itself, but not of library user. Thus a query string that includes "+" instead of white space may return unexpected result.
curl -X GET "https://api.github.com/search/repositories?order=desc&page=2&per_page=100&q=language%3Agolang+stars%3A%3E%3D200+pushed%3A%3E%3D2018-01-01&sort=stars"
curl -X GET "https://api.github.com/search/repositories?order=desc&page=2&per_page=100&q=language%3Agolang stars%3A%3E%3D200 pushed%3A%3E%3D2018-01-01&sort=stars" In case of using curl, escaping of query string is responsibility of user. Thus former case goes okay. |
Thank you for the analysis, @pankona! It is greatly appreciated! @gauntface - do you agree? TL;DR: #966 was the wrong fix for #963 - the query in #963 was malformed. This PR goes back to the original implementation. |
Ok, my understanding from everything is that this is the correct change. Forcing users to not do this:
And instead do this:
I like this approach just from the perspective of being close to the input you would provide to the Github.com search box. Regarding this PR, @pankona could you add a comment to the |
@gauntface
okay, I will. |
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.
One tiny nit, then LGTM.
Sorry I missed that before.
Thank you, @pankona!
Awaiting second LGTM before merge.
github/search.go
Outdated
@@ -218,20 +216,19 @@ func (s *SearchService) Labels(ctx context.Context, repoID int64, query string, | |||
|
|||
// Helper function that executes search queries against different | |||
// GitHub search types (repositories, commits, code, issues, users, labels) | |||
// | |||
// If *searchParameters.Query includes multiple condition, it MUST NOT include "+" as condition separator. |
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.
nit: please remove leading *
as we typically do not put these for pointers in Godocs.
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! fixed on 63ab8d9
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.
Great! Thank you, @pankona!
One more quick request since @gauntface hasn't reviewed yet, please...
Could you please add language:c++
to line 118 in search_test.go
just to make your comment super-clear in the test results for how it will look?
understood, I will! |
Perfect, @pankona ! Thank you! Awaiting @gauntface LGTM before merging. |
Gently ping to @gauntface :) |
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.
Sorry for the delayed LGTM. This looks great. Thank you so much for the change 🎉
Thank you @gauntface for your confirmation! If there's no concern for merging, could you please proceed? |
Thank you, @gauntface! |
Fixes #1122.