summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorpricly-yellow <79628427+pricly-yellow@users.noreply.github.com>2021-10-05 21:41:48 +0700
committerGitHub <noreply@github.com>2021-10-05 16:41:48 +0200
commit20eaca6d05ddeb56f5a76638e84211117c3f0131 (patch)
treee9ff51b835b58bcab4efd9cffd20cd720170b0cd /routers
parentf4ea6cc4b479de70ac2e82330f1a0d515f7fd50f (diff)
downloadgitea-20eaca6d05ddeb56f5a76638e84211117c3f0131.tar.gz
gitea-20eaca6d05ddeb56f5a76638e84211117c3f0131.zip
Fix stange behavior of DownloadPullDiffOrPatch in incorect index (#17223)
Fix GetPullRequestByIndex by validate index > 1 Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de> Co-authored-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/pull.go21
1 files changed, 4 insertions, 17 deletions
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 9c9cf0f21d..dde5561351 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1322,29 +1322,16 @@ func DownloadPullPatch(ctx *context.Context) {
// DownloadPullDiffOrPatch render a pull's raw diff or patch
func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.NotFound("GetIssueByIndex", err)
+ if models.IsErrPullRequestNotExist(err) {
+ ctx.NotFound("GetPullRequestByIndex", err)
} else {
- ctx.ServerError("GetIssueByIndex", err)
+ ctx.ServerError("GetPullRequestByIndex", err)
}
return
}
- // Return not found if it's not a pull request
- if !issue.IsPull {
- ctx.NotFound("DownloadPullDiff",
- fmt.Errorf("Issue is not a pull request"))
- return
- }
-
- if err = issue.LoadPullRequest(); err != nil {
- ctx.ServerError("LoadPullRequest", err)
- return
- }
-
- pr := issue.PullRequest
binary := ctx.FormBool("binary")
if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch, binary); err != nil {