diff --git a/output_yaml.go b/output_yaml.go index 0bb9286..d1423c6 100644 --- a/output_yaml.go +++ b/output_yaml.go @@ -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, " *&:,") } diff --git a/output_yaml_test.go b/output_yaml_test.go index 02fa739..972965d 100644 --- a/output_yaml_test.go +++ b/output_yaml_test.go @@ -372,6 +372,7 @@ data: bar: true and: null but: "null" + dash: "-" `) expected := `--- @@ -380,6 +381,7 @@ data: bar: true and: null but: "null" + dash: "-" ` var node yamlv3.Node