Skip to content

Commit

Permalink
Fix missing quotation for dashes
Browse files Browse the repository at this point in the history
Ref: homeport/dyff#342

Make sure to quote the dash in a string.
  • Loading branch information
HeavyWombat committed Feb 10, 2024
1 parent 480ed2f commit 39cb598
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions output_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ func needsQuotes(node *yamlv3.Node) bool {
}
}

// check if strings starts with a dash
if strings.HasPrefix(node.Value, "-") {
return true
}

// check if string contains special characters
return strings.ContainsAny(node.Value, " *&:,")
}
2 changes: 2 additions & 0 deletions output_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ data:
bar: true
and: null
but: "null"
dash: "-"
`)

expected := `---
Expand All @@ -380,6 +381,7 @@ data:
bar: true
and: null
but: "null"
dash: "-"
`

var node yamlv3.Node
Expand Down

0 comments on commit 39cb598

Please sign in to comment.