From 0163c443dc3b676b06306927be0565f0874af810 Mon Sep 17 00:00:00 2001 From: mo1ein Date: Tue, 13 Sep 2022 17:55:09 +0430 Subject: [PATCH 1/6] Fix unhandled error in actions_artifacts.go --- github/actions_artifacts.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 3b9c83c490..4320ea74b2 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, nil, err + } + return parsedURL, newResponse(resp), nil } From 5451f6c1d3a7cc43aa02ad6c1820c4d4ec14d3e2 Mon Sep 17 00:00:00 2001 From: Moein Halvaei <50274938+mo1ein@users.noreply.github.com> Date: Tue, 13 Sep 2022 18:23:51 +0430 Subject: [PATCH 2/6] Fix code style --- github/actions_artifacts.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 4320ea74b2..370bedf53c 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -121,9 +121,9 @@ func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo strin } parsedURL, err := url.Parse(resp.Header.Get("Location")) - if err != nil { - return nil, nil, err - } + if err != nil { + return nil, nil, err + } return parsedURL, newResponse(resp), nil } From dcd49c5686cb6469d04b3a5377ab2a9a0dbfd6c7 Mon Sep 17 00:00:00 2001 From: mo1ein Date: Tue, 13 Sep 2022 21:00:33 +0430 Subject: [PATCH 3/6] Fix code style with gofmt --- github/actions_artifacts.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 370bedf53c..3350e40e65 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -121,9 +121,9 @@ func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo strin } parsedURL, err := url.Parse(resp.Header.Get("Location")) - if err != nil { - return nil, nil, err - } + if err != nil { + return nil, nil, err + } return parsedURL, newResponse(resp), nil } From 9ff57ecd9bb32467df56aed2994e0bf60aacff6f Mon Sep 17 00:00:00 2001 From: mo1ein Date: Wed, 14 Sep 2022 02:56:19 +0430 Subject: [PATCH 4/6] Handle invalidLocation situation in actions_artifacts_test.go --- github/actions_artifacts_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index e35a873bc0..1488499890 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -368,6 +368,22 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_followRedirects( } } +func TestActionsService_DownloadArtifact_invalidLocationHeader(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + badLocationHeader := "http://\ngithub.com\ngoogle\ngo-github" + mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusOK) + w.Header().Set("Location", badLocationHeader) + }) + + 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() From 24ad5e307cd59c473c8537ed582c7c80c68a9a7a Mon Sep 17 00:00:00 2001 From: mo1ein Date: Thu, 15 Sep 2022 05:03:40 +0430 Subject: [PATCH 5/6] Fix TestActionsService_DownloadArtifact_invalidLocationHeader --- github/actions_artifacts_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index 1488499890..345a087534 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -372,11 +372,12 @@ func TestActionsService_DownloadArtifact_invalidLocationHeader(t *testing.T) { client, mux, _, teardown := setup() defer teardown() - badLocationHeader := "http://\ngithub.com\ngoogle\ngo-github" mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - w.WriteHeader(http.StatusOK) - w.Header().Set("Location", badLocationHeader) + ctlChar := 0x7f + badURL := "https://google.com" + string(byte(ctlChar)) + w.Header().Add("Location", badURL) + w.WriteHeader(http.StatusFound) }) ctx := context.Background() From 1ac8032ee43bec5ce9490f8e5a4262c19077b4de Mon Sep 17 00:00:00 2001 From: mo1ein Date: Thu, 15 Sep 2022 20:11:09 +0430 Subject: [PATCH 6/6] Fix return value --- github/actions_artifacts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 3350e40e65..99329d989d 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -122,7 +122,7 @@ func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo strin parsedURL, err := url.Parse(resp.Header.Get("Location")) if err != nil { - return nil, nil, err + return nil, newResponse(resp), err } return parsedURL, newResponse(resp), nil