Skip to content

Commit b559b3d

Browse files
committed
Handle too long PR titles correctly
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 go-gitea#16507 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 1ce4fb2 commit b559b3d

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

routers/web/repo/compare.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,15 @@ func PrepareCompareDiff(
567567
} else {
568568
title = headBranch
569569
}
570+
if len(title) > 255 {
571+
if ctx.Data["content"] != nil {
572+
ctx.Data["content"] = fmt.Sprintf("...%s\n\n%s", title[252:], ctx.Data["content"])
573+
} else {
574+
ctx.Data["content"] = "..." + title[252:] + "\n"
575+
}
576+
title = title[:252] + "..."
577+
}
578+
570579
ctx.Data["title"] = title
571580
ctx.Data["Username"] = headUser.Name
572581
ctx.Data["Reponame"] = headRepo.Name

routers/web/repo/pull.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
10011001
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
10021002
ctx.Data["PageIsComparePull"] = true
10031003
ctx.Data["IsDiffCompare"] = true
1004+
ctx.Data["IsRepoToolbarCommits"] = true
1005+
ctx.Data["RequireTribute"] = true
1006+
ctx.Data["RequireSimpleMDE"] = true
10041007
ctx.Data["RequireHighlightJS"] = true
10051008
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
10061009
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
10071010
upload.AddUploadContext(ctx, "comment")
1011+
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)
10081012

10091013
var (
10101014
repo = ctx.Repo.Repository
@@ -1037,6 +1041,12 @@ func CompareAndPullRequestPost(ctx *context.Context) {
10371041
return
10381042
}
10391043

1044+
if len(form.Title) > 255 {
1045+
form.Content = "..." + form.Title[252:] + "\n\n" + form.Content
1046+
form.Title = form.Title[:252] + "..."
1047+
}
1048+
middleware.AssignForm(form, ctx.Data)
1049+
10401050
ctx.HTML(http.StatusOK, tplCompareDiff)
10411051
return
10421052
}

templates/repo/diff/compare.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@
176176
{{if .IsNothingToCompare}}
177177
{{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived) }}
178178
<div class="ui segment">{{.i18n.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}</div>
179-
<div class="ui info message show-form-container">
179+
<div class="ui info message show-form-container" {{if .Flash}}style="display: none"{{end}}>
180180
<button class="ui button green show-form">{{.i18n.Tr "repo.pulls.new"}}</button>
181181
</div>
182-
<div class="pullrequest-form" style="display: none">
182+
<div class="pullrequest-form" {{if not .Flash}}style="display: none"{{end}}>
183183
{{template "repo/issue/new_form" .}}
184184
</div>
185185
{{else}}
@@ -192,7 +192,7 @@
192192
</div>
193193
{{else}}
194194
{{if and $.IsSigned (not .Repository.IsArchived)}}
195-
<div class="ui info message show-form-container">
195+
<div class="ui info message show-form-container" {{if .Flash}}style="display: none"{{end}}>
196196
<button class="ui button green show-form">{{.i18n.Tr "repo.pulls.new"}}</button>
197197
</div>
198198
{{else if .Repository.IsArchived}}
@@ -201,7 +201,7 @@
201201
</div>
202202
{{end}}
203203
{{if $.IsSigned}}
204-
<div class="pullrequest-form" style="display: none">
204+
<div class="pullrequest-form" {{if not .Flash}}style="display: none"{{end}}>
205205
{{template "repo/issue/new_form" .}}
206206
</div>
207207
{{end}}

0 commit comments

Comments
 (0)