From 39cb598866b3fd34c21cb91cbf87c0d3f77e0fbd Mon Sep 17 00:00:00 2001 From: Matthias Diester Date: Sat, 10 Feb 2024 22:53:41 +0100 Subject: [PATCH] Fix missing quotation for dashes Ref: https://github.com/homeport/dyff/issues/342 Make sure to quote the dash in a string. --- output_yaml.go | 5 +++++ output_yaml_test.go | 2 ++ 2 files changed, 7 insertions(+) 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