Skip to content

Commit

Permalink
Prevent NPE on commenting on lines with invalidated comments
Browse files Browse the repository at this point in the history
Only check for a review if we are replying to a previous review.

Prevent the NPE in go-gitea#12239 by assuming that a comment without a Review is
non-pending.

Fix go-gitea#12239

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Aug 20, 2020
1 parent 69a77b2 commit 309fd94
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion services/pull/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,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}}
<tr class="add-code-comment">
<td class="lines-num"></td>
<td class="lines-type-marker"></td>
Expand Down
5 changes: 4 additions & 1 deletion templates/repo/diff/section_unified.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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}}
<tr>
<td colspan="2" class="lines-num"></td>
<td class="add-comment-left add-comment-right" colspan="2">
Expand Down

0 comments on commit 309fd94

Please sign in to comment.