Skip to content

Commit

Permalink
fix(engine): Fixed comments commands on windows (#4497)
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Avelar <[email protected]>
  • Loading branch information
felipe-avelar authored Nov 10, 2021
1 parent f2d12d5 commit 25b6b70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions docs/running-kics.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ in this case only lines from 1 to 3 will be ignored.

`ignore-line` will ignore all lines of a multi-line command in Docker.

**NOTE**: For YAML when trying to ignore the whole resource this file should start with `---` and then the KICS comment command as you can see on the following example:
```yaml
1: ---
2: # kics-scan ignore-block
3: apiVersion: v1
4: kind: Pod
5: metadata:
6: name: memory-demo-1
7: namespace: mem-example
```
This feature is supported by all extensions that supports comments. Currently, KICS supports this feature for:
- Dockerfile;
- HCL (Terraform);
Expand Down
8 changes: 5 additions & 3 deletions pkg/model/comment_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func ignoreCommentsYAML(node *yaml.Node) {
}
// check if comment is in the content
for i, content := range node.Content {
if content.FootComment != "" && i+2 < len(node.Content) {
linesIgnore = append(linesIgnore, processCommentYAML((*comment)(&content.FootComment), i+2, node, node.Kind)...) //nolint
}
if content.HeadComment == "" {
continue
}
Expand Down Expand Up @@ -117,14 +120,13 @@ func getNodeLastLine(node *yaml.Node) (lastLine int) {
// value returns the value of the comment
func (c *comment) value() (value CommentCommand) {
comment := strings.ToLower(string(*c))

// check if we are working with kics command
if KICSCommentRgxp.MatchString(comment) {
comment = KICSCommentRgxp.ReplaceAllString(comment, "")
commands := strings.Split(strings.Trim(comment, "\n"), " ")
comment = strings.Trim(comment, "\n")
commands := strings.Split(strings.Trim(comment, "\r"), " ")
value = ProcessCommands(commands)
return
}

return CommentCommand(comment)
}
4 changes: 2 additions & 2 deletions pkg/parser/terraform/comment/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func (c *comment) value() (value model.CommentCommand) {
// check if we are working with kics command
if model.KICSCommentRgxp.MatchString(comment) {
comment = model.KICSCommentRgxp.ReplaceAllString(comment, "")
commands := strings.Split(strings.Trim(comment, "\n"), " ")
comment = strings.Trim(comment, "\n")
commands := strings.Split(strings.Trim(comment, "\r"), " ")
value = model.ProcessCommands(commands)
return
}

return model.CommentCommand(comment)
}

Expand Down

0 comments on commit 25b6b70

Please sign in to comment.