Merge pull request '[v8.0/forgejo] [BUG] Fix panic on too high page number' (#4606) from bp-v8.0/forgejo-6a49e3f into v8.0/forgejo
Some checks failed
/ release (push) Has been cancelled
testing / backend-checks (push) Has been cancelled
testing / frontend-checks (push) Has been cancelled
testing / test-unit (push) Has been cancelled
testing / test-remote-cacher (map[image:ghcr.io/microsoft/garnet-alpine:1.0.14 port:6379]) (push) Has been cancelled
testing / test-remote-cacher (map[image:redis:7.2 port:6379]) (push) Has been cancelled
testing / test-remote-cacher (map[image:registry.redict.io/redict:7.3.0-scratch port:6379]) (push) Has been cancelled
testing / test-mysql (push) Has been cancelled
testing / test-pgsql (push) Has been cancelled
testing / test-sqlite (push) Has been cancelled
testing / security-check (push) Has been cancelled

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4606
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-07-21 06:58:15 +00:00
commit c65534ce02
2 changed files with 24 additions and 0 deletions

View file

@ -242,6 +242,12 @@ func FileHistory(ctx *context.Context) {
ctx.ServerError("CommitsByFileAndRange", err)
return
}
if len(commits) == 0 {
ctx.NotFound("CommitsByFileAndRange", nil)
return
}
oldestCommit := commits[len(commits)-1]
renamedFiles, err := git.GetCommitFileRenames(ctx, ctx.Repo.GitRepo.Path, oldestCommit.ID.String())

View file

@ -1022,3 +1022,21 @@ func TestRepoCodeSearchForm(t *testing.T) {
testSearchForm(t, true)
})
}
func TestFileHistoryPager(t *testing.T) {
defer tests.PrepareTestEnv(t)()
t.Run("Normal page number", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master/README.md?page=1")
MakeRequest(t, req, http.StatusOK)
})
t.Run("Too high page number", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master/README.md?page=9999")
MakeRequest(t, req, http.StatusNotFound)
})
}