Skip to content

Commit

Permalink
🐛 fix special character in search query to fix fuzzing check (#1241)
Browse files Browse the repository at this point in the history
* fix fuzzing path separator

Signed-off-by: Asra Ali <[email protected]>

* add comment

Signed-off-by: Asra Ali <[email protected]>
  • Loading branch information
asraa authored Nov 15, 2021
1 parent 72e20a0 commit 5950fde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clients/githubrepo/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (handler *searchHandler) buildQuery(request clients.SearchRequest) (string,
}
var queryBuilder strings.Builder
if _, err := queryBuilder.WriteString(
fmt.Sprintf("%s repo:%s/%s", request.Query, handler.owner, handler.repo)); err != nil {
// The fuzzing check searches for GitHub URI, e.g. `github.com/org/repo`. The forward slash is one special character
// that should be replaced with a space.
// See https://docs.github.com/en/search-github/searching-on-github/searching-code#considerations-for-code-search
// for reference.
fmt.Sprintf("%s repo:%s/%s", strings.ReplaceAll(request.Query, "/", " "), handler.owner, handler.repo)); err != nil {
return "", fmt.Errorf("WriteString: %w", err)
}
if request.Filename != "" {
Expand Down
11 changes: 11 additions & 0 deletions clients/githubrepo/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ func TestBuildQuery(t *testing.T) {
},
expectedQuery: "testquery repo:testowner/testrepo in:file filename:filename1.txt path:dir1/dir2",
},
{
name: "WithFilenameAndPathWithSeparator",
owner: "testowner",
repo: "testrepo",
searchReq: clients.SearchRequest{
Query: "testquery/query",
Filename: "filename1.txt",
Path: "dir1/dir2",
},
expectedQuery: "testquery query repo:testowner/testrepo in:file filename:filename1.txt path:dir1/dir2",
},
}

for _, testcase := range testcases {
Expand Down

0 comments on commit 5950fde

Please sign in to comment.