Skip to content

Commit

Permalink
Add explicit error return (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
mo1ein authored Sep 17, 2022
1 parent d611561 commit 30d1431
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion github/repos_contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,9 @@ func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo st
}

parsedURL, err := url.Parse(resp.Header.Get("Location"))
return parsedURL, newResponse(resp), err
if err != nil {
return nil, newResponse(resp), err
}

return parsedURL, newResponse(resp), nil
}
17 changes: 17 additions & 0 deletions github/repos_contents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,23 @@ func TestRepositoriesService_GetArchiveLink_StatusMovedPermanently_followRedirec
}
}

func TestRepositoriesService_GetArchiveLink_invalidLocationHeader(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/tarball", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
ctlChar := 0x7f
badURL := "https://google.com" + string(byte(ctlChar))
w.Header().Add("Location", badURL)
w.WriteHeader(http.StatusFound)
})

ctx := context.Background()
_, _, err := client.Repositories.GetArchiveLink(ctx, "o", "r", Tarball, &RepositoryContentGetOptions{}, false)
testURLParseError(t, err)
}

func TestRepositoriesService_GetContents_NoTrailingSlashInDirectoryApiPath(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down

0 comments on commit 30d1431

Please sign in to comment.