From 03ba12aabf95ced8398c7859deff76780a4577cd Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 21 Aug 2020 08:52:20 +0100 Subject: [PATCH] Prevent NPE on commenting on lines with invalidated comments (#12549) (#12550) * Prevent NPE on commenting on lines with invalidated comments Only check for a review if we are replying to a previous review. Prevent the NPE in #12239 by assuming that a comment without a Review is non-pending. Fix #12239 Signed-off-by: Andrew Thornton * Add hack around to show the broken comments Signed-off-by: Andrew Thornton --- services/pull/review.go | 2 +- templates/repo/diff/box.tmpl | 5 +- templates/repo/diff/section_unified.tmpl | 5 +- .../repo/issue/view_content/comments.tmpl | 116 ++++++++++++++++++ 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/services/pull/review.go b/services/pull/review.go index 25e0ca858..5a77a4da1 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -29,7 +29,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models // - Comments that are part of a review // - Comments that reply to an existing review - if !isReview { + if !isReview && replyReviewID != 0 { // It's not part of a review; maybe a reply to a review comment or a single comment. // Check if there are reviews for that line already; if there are, this is a reply if existsReview, err = models.ReviewExists(issue, treePath, line); err != nil { diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index b6d1fdf3a..1f4484fb1 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -149,7 +149,10 @@ {{if gt (len $line.Comments) 0}} {{$resolved := (index $line.Comments 0).IsResolved}} {{$resolveDoer := (index $line.Comments 0).ResolveDoer}} - {{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}} + {{$isNotPending := false}} + {{if (index $line.Comments 0).Review}} + {{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}} + {{end}} diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index 707822e45..0a0849bad 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -25,7 +25,10 @@ {{if gt (len $line.Comments) 0}} {{$resolved := (index $line.Comments 0).IsResolved}} {{$resolveDoer := (index $line.Comments 0).ResolveDoer}} - {{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}} + {{$isNotPending := false}} + {{if (index $line.Comments 0).Review}} + {{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}} + {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 0a146513a..7611e390c 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -366,6 +366,122 @@ {{end}} + {{else if and (eq .Type 21) (eq .ReviewID 0)}} +
+
+ {{if .OriginalAuthor }} + {{else}} + + + + {{end}} + {{svg "octicon-comment" 16}} + + {{if .OriginalAuthor }} + {{ .OriginalAuthor }} {{if $.Repository.OriginalURL}}({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}} + {{else}} + {{.Poster.GetDisplayName}} + {{end}} + {{$.i18n.Tr "repo.issues.review.comment" $createdStr | Safe}} + +
+
+ {{$filename := .TreePath}} + {{$line := .Line}} +
+
+ {{$invalid := .Invalidated}} + {{$resolved := .IsResolved}} + {{$ignore := .LoadResolveDoer}} + {{$resolveDoer := .ResolveDoer}} + {{$isNotPending := true}} + {{if or $invalid $resolved}} + + + {{end}} + {{$filename}} +
+ {{$diff := (CommentMustAsDiff .)}} + {{if $diff}} + {{$file := (index $diff.Files 0)}} +
+
+
+ + + {{template "repo/diff/section_unified" dict "file" $file "root" $}} + +
+
+
+
+ {{end}} +
+
+ {{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.Lang }} +
+ {{if not .OriginalAuthor }} + + + + {{end}} +
+
+ + {{if .OriginalAuthor }} + {{ .OriginalAuthor }} {{if $.Repository.OriginalURL}}({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}} + {{else}} + {{.Poster.GetDisplayName}} + {{end}} + {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdSubStr | Safe}} +
+
+ {{if .RenderedContent}} + {{.RenderedContent|Str2html}} + {{else}} + {{$.i18n.Tr "repo.issues.no_content"}} + {{end}} +
+
{{.Content}}
+
+
+
+
+
+
+ {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" .ReviewID "root" $ "comment" .}} + + {{if and $.CanMarkConversation $isNotPending}} + + {{end}} + + {{if $resolved}} + {{$resolveDoer.Name}} {{$.i18n.Tr "repo.issues.review.resolved_by"}} + {{end}} +
+
+
+
{{else if eq .Type 22}}