Skip to content

Commit 30d1431

Browse files
authored
Add explicit error return (#2469)
1 parent d611561 commit 30d1431

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

github/repos_contents.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,9 @@ func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo st
317317
}
318318

319319
parsedURL, err := url.Parse(resp.Header.Get("Location"))
320-
return parsedURL, newResponse(resp), err
320+
if err != nil {
321+
return nil, newResponse(resp), err
322+
}
323+
324+
return parsedURL, newResponse(resp), nil
321325
}

github/repos_contents_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,23 @@ func TestRepositoriesService_GetArchiveLink_StatusMovedPermanently_followRedirec
744744
}
745745
}
746746

747+
func TestRepositoriesService_GetArchiveLink_invalidLocationHeader(t *testing.T) {
748+
client, mux, _, teardown := setup()
749+
defer teardown()
750+
751+
mux.HandleFunc("/repos/o/r/tarball", func(w http.ResponseWriter, r *http.Request) {
752+
testMethod(t, r, "GET")
753+
ctlChar := 0x7f
754+
badURL := "https://google.com" + string(byte(ctlChar))
755+
w.Header().Add("Location", badURL)
756+
w.WriteHeader(http.StatusFound)
757+
})
758+
759+
ctx := context.Background()
760+
_, _, err := client.Repositories.GetArchiveLink(ctx, "o", "r", Tarball, &RepositoryContentGetOptions{}, false)
761+
testURLParseError(t, err)
762+
}
763+
747764
func TestRepositoriesService_GetContents_NoTrailingSlashInDirectoryApiPath(t *testing.T) {
748765
client, mux, _, teardown := setup()
749766
defer teardown()

0 commit comments

Comments
 (0)