aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2023-07-06 02:52:12 +0800
committerGitHub <noreply@github.com>2023-07-05 18:52:12 +0000
commit3c05aa49278d6a540cc894f46230f379c3aade62 (patch)
tree58e7fd220ed0d6a9bb60c30afdd89db50a887d79 /routers
parentc0edb9b78b631c925ed6e868050336a0c6a529c7 (diff)
downloadgitea-3c05aa49278d6a540cc894f46230f379c3aade62.tar.gz
gitea-3c05aa49278d6a540cc894f46230f379c3aade62.zip
Check `ctx.Written()` for `GetActionIssue` (#25698)
Fix #25697. Just avoid panic, maybe there's another bug to trigger this case. --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/issue.go5
-rw-r--r--routers/web/repo/issue_content_history.go10
-rw-r--r--routers/web/repo/issue_pin.go3
-rw-r--r--routers/web/repo/pull.go2
-rw-r--r--routers/web/repo/pull_review.go11
5 files changed, 20 insertions, 11 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 5e15df330c..6acfc87d5e 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -1977,7 +1977,7 @@ func GetActionIssue(ctx *context.Context) *issues_model.Issue {
return nil
}
if err = issue.LoadAttributes(ctx); err != nil {
- ctx.ServerError("LoadAttributes", nil)
+ ctx.ServerError("LoadAttributes", err)
return nil
}
return issue
@@ -3282,6 +3282,9 @@ func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error {
// GetIssueAttachments returns attachments for the issue
func GetIssueAttachments(ctx *context.Context) {
issue := GetActionIssue(ctx)
+ if ctx.Written() {
+ return
+ }
attachments := make([]*api.Attachment, len(issue.Attachments))
for i := 0; i < len(issue.Attachments); i++ {
attachments[i] = convert.ToAttachment(issue.Attachments[i])
diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go
index 46a320a8cc..3dd7725c21 100644
--- a/routers/web/repo/issue_content_history.go
+++ b/routers/web/repo/issue_content_history.go
@@ -24,7 +24,7 @@ import (
// GetContentHistoryOverview get overview
func GetContentHistoryOverview(ctx *context.Context) {
issue := GetActionIssue(ctx)
- if issue == nil {
+ if ctx.Written() {
return
}
@@ -43,11 +43,11 @@ func GetContentHistoryOverview(ctx *context.Context) {
// GetContentHistoryList get list
func GetContentHistoryList(ctx *context.Context) {
issue := GetActionIssue(ctx)
- commentID := ctx.FormInt64("comment_id")
- if issue == nil {
+ if ctx.Written() {
return
}
+ commentID := ctx.FormInt64("comment_id")
items, _ := issues_model.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
// render history list to HTML for frontend dropdown items: (name, value)
@@ -113,7 +113,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *issues_model.Issue
// GetContentHistoryDetail get detail
func GetContentHistoryDetail(ctx *context.Context) {
issue := GetActionIssue(ctx)
- if issue == nil {
+ if ctx.Written() {
return
}
@@ -179,7 +179,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
// SoftDeleteContentHistory soft delete
func SoftDeleteContentHistory(ctx *context.Context) {
issue := GetActionIssue(ctx)
- if issue == nil {
+ if ctx.Written() {
return
}
diff --git a/routers/web/repo/issue_pin.go b/routers/web/repo/issue_pin.go
index 7c1a306e6c..871ca3b333 100644
--- a/routers/web/repo/issue_pin.go
+++ b/routers/web/repo/issue_pin.go
@@ -15,6 +15,9 @@ import (
// IssuePinOrUnpin pin or unpin a Issue
func IssuePinOrUnpin(ctx *context.Context) {
issue := GetActionIssue(ctx)
+ if ctx.Written() {
+ return
+ }
// If we don't do this, it will crash when trying to add the pin event to the comment history
err := issue.LoadRepo(ctx)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index ad04fb2d71..e0a618bf59 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1491,10 +1491,10 @@ func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
// UpdatePullRequestTarget change pull request's target branch
func UpdatePullRequestTarget(ctx *context.Context) {
issue := GetActionIssue(ctx)
- pr := issue.PullRequest
if ctx.Written() {
return
}
+ pr := issue.PullRequest
if !issue.IsPull {
ctx.Error(http.StatusNotFound)
return
diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go
index 1645155bf8..f7c962d1ae 100644
--- a/routers/web/repo/pull_review.go
+++ b/routers/web/repo/pull_review.go
@@ -28,6 +28,9 @@ const (
// RenderNewCodeCommentForm will render the form for creating a new review comment
func RenderNewCodeCommentForm(ctx *context.Context) {
issue := GetActionIssue(ctx)
+ if ctx.Written() {
+ return
+ }
if !issue.IsPull {
return
}
@@ -52,10 +55,10 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
func CreateCodeComment(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CodeCommentForm)
issue := GetActionIssue(ctx)
- if !issue.IsPull {
+ if ctx.Written() {
return
}
- if ctx.Written() {
+ if !issue.IsPull {
return
}
@@ -185,10 +188,10 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
func SubmitReview(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.SubmitReviewForm)
issue := GetActionIssue(ctx)
- if !issue.IsPull {
+ if ctx.Written() {
return
}
- if ctx.Written() {
+ if !issue.IsPull {
return
}
if ctx.HasError() {