From d6115619cf61ccadd1925403243a8d1eb0f06966 Mon Sep 17 00:00:00 2001 From: Moein Halvaei <50274938+mo1ein@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:03:16 +0430 Subject: [PATCH] Fix unhandled error in actions_artifacts.go (#2460) --- github/actions_artifacts.go | 4 ++++ github/actions_artifacts_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) 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()