diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 3b9c83c490..99329d989d 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -121,6 +121,10 @@ func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo strin } parsedURL, err := url.Parse(resp.Header.Get("Location")) + if err != nil { + return nil, newResponse(resp), err + } + return parsedURL, newResponse(resp), nil } diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index e35a873bc0..345a087534 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -368,6 +368,23 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_followRedirects( } } +func TestActionsService_DownloadArtifact_invalidLocationHeader(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", 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.Actions.DownloadArtifact(ctx, "o", "r", 1, false) + testURLParseError(t, err) +} + func TestActionsService_DeleteArtifact(t *testing.T) { client, mux, _, teardown := setup() defer teardown()