Skip to content

Commit ca58692

Browse files
authored
Make sure no attempts to create empty comment for PR Scan on split (#848)
1 parent 72877f9 commit ca58692

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

utils/outputwriter/outputcontent_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ func TestVulnerabilitiesContent(t *testing.T) {
358358
{
359359
name: "Standard output",
360360
writer: &StandardOutput{},
361-
expectedOutput: []string{""},
361+
expectedOutput: []string{},
362362
},
363363
{
364364
name: "Simplified output",
365365
writer: &SimplifiedOutput{},
366-
expectedOutput: []string{""},
366+
expectedOutput: []string{},
367367
},
368368
},
369369
},
@@ -496,12 +496,12 @@ func TestSecurityViolationsContent(t *testing.T) {
496496
{
497497
name: "Standard output",
498498
writer: &StandardOutput{},
499-
expectedOutput: []string{""},
499+
expectedOutput: []string{},
500500
},
501501
{
502502
name: "Simplified output",
503503
writer: &SimplifiedOutput{},
504-
expectedOutput: []string{""},
504+
expectedOutput: []string{},
505505
},
506506
},
507507
},

utils/outputwriter/outputwriter.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,23 @@ func WriteNewLine(builder *strings.Builder) {
249249
func ConvertContentToComments(content []string, writer OutputWriter, commentDecorators ...CommentDecorator) (comments []string) {
250250
commentBuilder := strings.Builder{}
251251
for _, commentContent := range content {
252-
if newContent, limitReached := getContentAndResetBuilderIfLimitReached(len(comments), commentContent, &commentBuilder, writer, commentDecorators...); limitReached {
252+
if newContent, limitReached := getContentAndResetBuilderIfLimitReached(len(comments), commentContent, &commentBuilder, writer, commentDecorators...); limitReached && newContent != "" {
253253
comments = append(comments, newContent)
254254
}
255255
WriteContent(&commentBuilder, commentContent)
256256
}
257257
if commentBuilder.Len() > 0 || len(content) == 0 {
258-
comments = append(comments, decorate(len(comments), commentBuilder.String(), commentDecorators...))
258+
if comment := decorate(len(comments), commentBuilder.String(), commentDecorators...); comment != "" {
259+
comments = append(comments, comment)
260+
}
259261
}
260262
return
261263
}
262264

263265
func getContentAndResetBuilderIfLimitReached(commentCount int, newContent string, builder *strings.Builder, writer OutputWriter, commentDecorators ...CommentDecorator) (content string, reached bool) {
264266
limit := writer.SizeLimit(commentCount != 0)
265-
if limit == 0 {
266-
// No limit
267+
if limit <= 0 {
268+
// No limit
267269
return
268270
}
269271
if builder.Len()+decoratorsSize(commentCount, commentDecorators...)+len(newContent) < limit {

0 commit comments

Comments
 (0)