Skip to content

Commit

Permalink
fix: escape double-quote in rule expr and annotation value
Browse files Browse the repository at this point in the history
  • Loading branch information
fgouteroux committed Oct 4, 2022
1 parent e17fa5e commit 2b3cc35
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func main() {
ruleExpr := strings.TrimSuffix(rule.Expr.Value, "\n")
if strings.Contains(ruleExpr, "\n") {
resource += fmt.Sprintf("expr = <<EOT\n%s\nEOT\n", ruleExpr)
} else if strings.Contains(ruleExpr, "\""){
resource += fmt.Sprintf("expr = \"%s\"\n", strings.ReplaceAll(ruleExpr, "\"", "\\\""))
} else {
resource += fmt.Sprintf("expr = \"%s\"\n", ruleExpr)
}
Expand All @@ -106,7 +108,7 @@ func main() {
if len(rule.Annotations) > 0 {
resource += fmt.Sprintf("annotations = {\n")
for aname, avalue := range rule.Annotations {
resource += fmt.Sprintf("%s = \"%s\"\n", aname, avalue)
resource += fmt.Sprintf("%s = \"%s\"\n", aname, strings.ReplaceAll(avalue, "\"", "\\\""))
}
resource += fmt.Sprintf("}\n")
}
Expand Down Expand Up @@ -142,6 +144,8 @@ func main() {
ruleExpr := strings.TrimSuffix(rule.Expr.Value, "\n")
if strings.Contains(ruleExpr, "\n") {
resource += fmt.Sprintf("expr = <<EOT\n%s\nEOT\n", ruleExpr)
} else if strings.Contains(ruleExpr, "\""){
resource += fmt.Sprintf("expr = \"%s\"\n", strings.ReplaceAll(ruleExpr, "\"", "\\\""))
} else {
resource += fmt.Sprintf("expr = \"%s\"\n", ruleExpr)
}
Expand Down

0 comments on commit 2b3cc35

Please sign in to comment.