aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-07-25 03:59:27 +0100
committerGitHub <noreply@github.com>2021-07-25 03:59:27 +0100
commitfd15fd4c67b22189a18765f888bb3f19e241acbe (patch)
tree56fd40a181097b3741de636179bb370c2a3ce448 /routers
parent4f23624b1674d87142c12ad8a868630c0d2e297f (diff)
downloadgitea-fd15fd4c67b22189a18765f888bb3f19e241acbe.tar.gz
gitea-fd15fd4c67b22189a18765f888bb3f19e241acbe.zip
Handle too long PR titles correctly (#16517)
The CompareAndPullRequestPost handler for POST to /compare incorrectly handles returning errors to the user. For a start it does not set the necessary markers to switch SimpleMDE but it also does not immediately return to the form. This PR fixes this by setting the appropriate values, fixing the templates and preventing the suggestion of a too long title. Fix #16507 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/compare.go13
-rw-r--r--routers/web/repo/pull.go12
2 files changed, 25 insertions, 0 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index fddfc4a63a..e66aa614cb 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/upload"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
)
@@ -567,6 +568,18 @@ func PrepareCompareDiff(
} else {
title = headBranch
}
+ if len(title) > 255 {
+ var trailer string
+ title, trailer = util.SplitStringAtByteN(title, 255)
+ if len(trailer) > 0 {
+ if ctx.Data["content"] != nil {
+ ctx.Data["content"] = fmt.Sprintf("%s\n\n%s", trailer, ctx.Data["content"])
+ } else {
+ ctx.Data["content"] = trailer + "\n"
+ }
+ }
+ }
+
ctx.Data["title"] = title
ctx.Data["Username"] = headUser.Name
ctx.Data["Reponame"] = headRepo.Name
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index a299799647..703bbd837a 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1001,10 +1001,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
+ ctx.Data["IsRepoToolbarCommits"] = true
+ ctx.Data["RequireTribute"] = true
+ ctx.Data["RequireSimpleMDE"] = true
ctx.Data["RequireHighlightJS"] = true
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
upload.AddUploadContext(ctx, "comment")
+ ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)
var (
repo = ctx.Repo.Repository
@@ -1037,6 +1041,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
return
}
+ if len(form.Title) > 255 {
+ var trailer string
+ form.Title, trailer = util.SplitStringAtByteN(form.Title, 255)
+
+ form.Content = trailer + "\n\n" + form.Content
+ }
+ middleware.AssignForm(form, ctx.Data)
+
ctx.HTML(http.StatusOK, tplCompareDiff)
return
}