Use url.QueryEscape instead of url.PathEscape to escape query string#1125
Conversation
|
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. |
| // 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.
nit: please remove leading * as we typically do not put these for pointers in Godocs.
gmlewis
left a comment
There was a problem hiding this comment.
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 :) |
gauntface
left a comment
There was a problem hiding this comment.
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? |

Fixes #1122.