Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-12-01 06:16:09 +01:00

Merge pull request '[v7.0/forgejo] Fix panic on too high page number' (#4623) from gusted/forgejo-commit-panic-bp-bp into v7.0/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4623
Reviewed-by: twenty-panda <twenty-panda@noreply.codeberg.org>
This commit is contained in:
Gusted 2024-07-22 21:58:25 +00:00
commit 8d8cd3aad8
2 changed files with 24 additions and 0 deletions

View file

@ -244,6 +244,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

@ -995,3 +995,21 @@ func TestViewRepoOpenWith(t *testing.T) {
testOpenWith([]string{"test://"})
})
}
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)
})
}