Skip to content

Commit 03cacf9

Browse files
GiteaBotwolfogre
andauthored
Check ctx.Written() for GetActionIssue (go-gitea#25698) (go-gitea#25711)
Backport go-gitea#25698 by @wolfogre Fix go-gitea#25697. Just avoid panic, maybe there's another bug to trigger this case. Co-authored-by: Jason Song <i@wolfogre.com>
1 parent 68e0c80 commit 03cacf9

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

routers/web/repo/issue.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ func GetActionIssue(ctx *context.Context) *issues_model.Issue {
19581958
return nil
19591959
}
19601960
if err = issue.LoadAttributes(ctx); err != nil {
1961-
ctx.ServerError("LoadAttributes", nil)
1961+
ctx.ServerError("LoadAttributes", err)
19621962
return nil
19631963
}
19641964
return issue
@@ -3258,6 +3258,9 @@ func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error {
32583258
// GetIssueAttachments returns attachments for the issue
32593259
func GetIssueAttachments(ctx *context.Context) {
32603260
issue := GetActionIssue(ctx)
3261+
if ctx.Written() {
3262+
return
3263+
}
32613264
attachments := make([]*api.Attachment, len(issue.Attachments))
32623265
for i := 0; i < len(issue.Attachments); i++ {
32633266
attachments[i] = convert.ToAttachment(issue.Attachments[i])

routers/web/repo/issue_content_history.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// GetContentHistoryOverview get overview
2525
func GetContentHistoryOverview(ctx *context.Context) {
2626
issue := GetActionIssue(ctx)
27-
if issue == nil {
27+
if ctx.Written() {
2828
return
2929
}
3030

@@ -43,11 +43,11 @@ func GetContentHistoryOverview(ctx *context.Context) {
4343
// GetContentHistoryList get list
4444
func GetContentHistoryList(ctx *context.Context) {
4545
issue := GetActionIssue(ctx)
46-
commentID := ctx.FormInt64("comment_id")
47-
if issue == nil {
46+
if ctx.Written() {
4847
return
4948
}
5049

50+
commentID := ctx.FormInt64("comment_id")
5151
items, _ := issues_model.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
5252

5353
// render history list to HTML for frontend dropdown items: (name, value)
@@ -113,7 +113,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *issues_model.Issue
113113
// GetContentHistoryDetail get detail
114114
func GetContentHistoryDetail(ctx *context.Context) {
115115
issue := GetActionIssue(ctx)
116-
if issue == nil {
116+
if ctx.Written() {
117117
return
118118
}
119119

@@ -179,7 +179,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
179179
// SoftDeleteContentHistory soft delete
180180
func SoftDeleteContentHistory(ctx *context.Context) {
181181
issue := GetActionIssue(ctx)
182-
if issue == nil {
182+
if ctx.Written() {
183183
return
184184
}
185185

routers/web/repo/issue_pin.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
// IssuePinOrUnpin pin or unpin a Issue
1616
func IssuePinOrUnpin(ctx *context.Context) {
1717
issue := GetActionIssue(ctx)
18+
if ctx.Written() {
19+
return
20+
}
1821

1922
// If we don't do this, it will crash when trying to add the pin event to the comment history
2023
err := issue.LoadRepo(ctx)

routers/web/repo/pull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,10 @@ func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
14701470
// UpdatePullRequestTarget change pull request's target branch
14711471
func UpdatePullRequestTarget(ctx *context.Context) {
14721472
issue := GetActionIssue(ctx)
1473-
pr := issue.PullRequest
14741473
if ctx.Written() {
14751474
return
14761475
}
1476+
pr := issue.PullRequest
14771477
if !issue.IsPull {
14781478
ctx.Error(http.StatusNotFound)
14791479
return

routers/web/repo/pull_review.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const (
2828
// RenderNewCodeCommentForm will render the form for creating a new review comment
2929
func RenderNewCodeCommentForm(ctx *context.Context) {
3030
issue := GetActionIssue(ctx)
31+
if ctx.Written() {
32+
return
33+
}
3134
if !issue.IsPull {
3235
return
3336
}
@@ -52,10 +55,10 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
5255
func CreateCodeComment(ctx *context.Context) {
5356
form := web.GetForm(ctx).(*forms.CodeCommentForm)
5457
issue := GetActionIssue(ctx)
55-
if !issue.IsPull {
58+
if ctx.Written() {
5659
return
5760
}
58-
if ctx.Written() {
61+
if !issue.IsPull {
5962
return
6063
}
6164

@@ -185,10 +188,10 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
185188
func SubmitReview(ctx *context.Context) {
186189
form := web.GetForm(ctx).(*forms.SubmitReviewForm)
187190
issue := GetActionIssue(ctx)
188-
if !issue.IsPull {
191+
if ctx.Written() {
189192
return
190193
}
191-
if ctx.Written() {
194+
if !issue.IsPull {
192195
return
193196
}
194197
if ctx.HasError() {

0 commit comments

Comments
 (0)