Merge pull request '[BUG] Fix panic on too high page number' (#4603) from gusted/forgejo-commit-panic into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4603 Reviewed-by: Gergely Nagy <algernon@noreply.codeberg.org>
This commit is contained in:
		
				commit
				
					
						914f75533f
					
				
			
		
					 2 changed files with 24 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue