diff options
author | qwerty287 <80460567+qwerty287@users.noreply.github.com> | 2022-10-26 17:46:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 23:46:11 +0800 |
commit | 8430f738e296cd82f318744e2a9ddf74be27c353 (patch) | |
tree | c0a8408aa4f8e54d9d11ebad09fe0e70a39c34d4 /routers | |
parent | ed47d0062e62ddd23c16687fbd5665a8ffe6912f (diff) | |
download | gitea-8430f738e296cd82f318744e2a9ddf74be27c353.tar.gz gitea-8430f738e296cd82f318744e2a9ddf74be27c353.zip |
Fix 500 on PR files API (#21602)
Fixes an 500 error/panic if using the changed PR files API with pages
that should return empty lists because there are no items anymore.
`start-end` is then < 0 which ends in panic.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/pull.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index f6507dceba..ebb9c0f261 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1443,7 +1443,11 @@ func GetPullRequestFiles(ctx *context.APIContext) { end = totalNumberOfFiles } - apiFiles := make([]*api.ChangedFile, 0, end-start) + lenFiles := end - start + if lenFiles < 0 { + lenFiles = 0 + } + apiFiles := make([]*api.ChangedFile, 0, lenFiles) for i := start; i < end; i++ { apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID)) } |