Repository: Checkmarx/kics (language: python)

Issue:
No issues detected when multiple comments on CloudFormation
### Actual Behavior

Multiple comments breaks detection on CloudFormation.


### Steps to Reproduce the Problem

Scanning the following YAML code won't detect issues because of the comments.


```yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Test

Resources:
  ################################
  #####      SomeTitle       #####
  ################################
  TestName:
    Type: AWS::ApiGatewayV2::DomainName
    Properties:
      DomainName: Test

Outputs:
  TestEndpoint:
    Description: Test
```

```yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Test

Resources:
  ##
  TestName:
    Type: AWS::ApiGatewayV2::DomainName
    Properties:
      DomainName: Test

Outputs:
  TestEndpoint:
    Description: Test
```

```yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Test

Resources:
  TestName:
    Type: AWS::ApiGatewayV2::DomainName
    Properties:
      DomainName: Test

###############################
####      SomeTitle       #####
###############################
Outputs:
  TestEndpoint:
    Description: Test
```

```yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Test

Resources:
  TestName:
    Type: AWS::ApiGatewayV2::DomainName
    Properties:
      DomainName: Test

#######
Outputs:
  TestEndpoint:
    Description: Test
```


Discussion / hints:

Fix patch:
diff --git a/pkg/model/comment_yaml.go b/pkg/model/comment_yaml.go
index d3ff7f6df7e..543f19ce05e 100644
--- a/pkg/model/comment_yaml.go
+++ b/pkg/model/comment_yaml.go
@@ -121,7 +121,7 @@ func processRegularLine(comment string, content *yaml.Node, position int, isFoot
 	}
 
 	line := content.Content[position].Line
-	commentsNumber := strings.Count(comment, "#") // number of comments (coverage of nested comments)
+	commentsNumber := strings.Count(comment, "\n") + 1 // number of comments (coverage of nested comments)
 
 	if isFooter { // comment is a foot comment
 		return getFootComments(comment, content, position, commentsNumber)


Test patch:
diff --git a/pkg/model/comment_yaml_test.go b/pkg/model/comment_yaml_test.go
index e451a7815d9..fbbd3a9301a 100644
--- a/pkg/model/comment_yaml_test.go
+++ b/pkg/model/comment_yaml_test.go
@@ -548,6 +548,92 @@ func Test_ignoreCommentsYAML(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "test_6: ignore_multiple_#",
+			want: []int{2, 3, 4},
+			args: args{
+				&yaml.Node{
+					Kind: yaml.MappingNode,
+					Content: []*yaml.Node{
+						{
+							Kind:  yaml.ScalarNode,
+							Value: "key",
+							Line:  1,
+						},
+						{
+							Kind:  yaml.ScalarNode,
+							Value: "false",
+							Tag:   "!!bool",
+						},
+						{
+							Kind:        yaml.ScalarNode,
+							HeadComment: "################################\n#####      SomeTitle       #####\n################################",
+							Value:       "seq_object",
+							Line:        5,
+						},
+						{
+							Kind: yaml.SequenceNode,
+							Line: 6,
+							Content: []*yaml.Node{
+								{
+									Kind: yaml.MappingNode,
+									Line: 6,
+									Content: []*yaml.Node{
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "key_seq",
+											Line:  6,
+										},
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "key_val",
+											Tag:   " !!str",
+											Line:  6,
+										},
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "key_seq_2",
+											Line:  7,
+										},
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "key_val_2",
+											Tag:   " !!str",
+											Line:  7,
+										},
+									},
+								},
+								{
+									Kind: yaml.MappingNode,
+									Content: []*yaml.Node{
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "second_key",
+											Line:  8,
+										},
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "second_val",
+											Tag:   " !!str",
+										},
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "second_key_2",
+											Line:  9,
+										},
+										{
+											Kind:  yaml.ScalarNode,
+											Value: "second_val_2",
+											Tag:   " !!str",
+										},
+									},
+								},
+							},
+						},
+					},
+				},
+			},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {