diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 1c4fb39546..2e8ca61bf5 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -474,7 +474,7 @@ func Download(ctx *context.Context) { uri := ctx.Params("*") ext, tp, err := archiver_service.ParseFileName(uri) if err != nil { - ctx.ServerError("ParseFileName", err) + ctx.NotFound("ParseFileName", err) return } aReq, err := archiver_service.NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, strings.TrimSuffix(uri, ext), tp) @@ -554,7 +554,7 @@ func InitiateDownload(ctx *context.Context) { uri := ctx.Params("*") ext, tp, err := archiver_service.ParseFileName(uri) if err != nil { - ctx.ServerError("ParseFileName", err) + ctx.NotFound("ParseFileName", err) return } aReq, err := archiver_service.NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, strings.TrimSuffix(uri, ext), tp) diff --git a/tests/integration/repo_archive_test.go b/tests/integration/repo_archive_test.go index a5c076952c..aea500b9b1 100644 --- a/tests/integration/repo_archive_test.go +++ b/tests/integration/repo_archive_test.go @@ -39,6 +39,10 @@ func TestRepoDownloadArchive(t *testing.T) { require.NoError(t, err) assert.Empty(t, resp.Header().Get("Content-Encoding")) assert.Len(t, bs, 320) + + // Verify that unrecognized archive type returns 404 + req = NewRequest(t, "GET", "/user2/repo1/archive/master.invalid") + MakeRequest(t, req, http.StatusNotFound) } func TestRepoDownloadArchiveSubdir(t *testing.T) {