Skip to content

Commit 309fd94

Browse files
committed
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 go-gitea#12239 by assuming that a comment without a Review is non-pending. Fix go-gitea#12239 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 69a77b2 commit 309fd94

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

services/pull/review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
2929
// - Comments that are part of a review
3030
// - Comments that reply to an existing review
3131

32-
if !isReview {
32+
if !isReview && replyReviewID != 0 {
3333
// It's not part of a review; maybe a reply to a review comment or a single comment.
3434
// Check if there are reviews for that line already; if there are, this is a reply
3535
if existsReview, err = models.ReviewExists(issue, treePath, line); err != nil {

templates/repo/diff/box.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@
155155
{{if gt (len $line.Comments) 0}}
156156
{{$resolved := (index $line.Comments 0).IsResolved}}
157157
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
158-
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
158+
{{$isNotPending := false}}
159+
{{if (index $line.Comments 0).Review}}
160+
{{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}}
161+
{{end}}
159162
<tr class="add-code-comment">
160163
<td class="lines-num"></td>
161164
<td class="lines-type-marker"></td>

templates/repo/diff/section_unified.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
{{if gt (len $line.Comments) 0}}
3636
{{$resolved := (index $line.Comments 0).IsResolved}}
3737
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
38-
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
38+
{{$isNotPending := false}}
39+
{{if (index $line.Comments 0).Review}}
40+
{{$isNotPending = (not (eq (index $line.Comments 0).Review.Type 0))}}
41+
{{end}}
3942
<tr>
4043
<td colspan="2" class="lines-num"></td>
4144
<td class="add-comment-left add-comment-right" colspan="2">

0 commit comments

Comments
 (0)