Skip to content

Commit 39cb598

Browse files
committed
Fix missing quotation for dashes
Ref: homeport/dyff#342 Make sure to quote the dash in a string.
1 parent 480ed2f commit 39cb598

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

output_yaml.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ func needsQuotes(node *yamlv3.Node) bool {
362362
}
363363
}
364364

365+
// check if strings starts with a dash
366+
if strings.HasPrefix(node.Value, "-") {
367+
return true
368+
}
369+
365370
// check if string contains special characters
366371
return strings.ContainsAny(node.Value, " *&:,")
367372
}

output_yaml_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ data:
372372
bar: true
373373
and: null
374374
but: "null"
375+
dash: "-"
375376
`)
376377

377378
expected := `---
@@ -380,6 +381,7 @@ data:
380381
bar: true
381382
and: null
382383
but: "null"
384+
dash: "-"
383385
`
384386

385387
var node yamlv3.Node

0 commit comments

Comments
 (0)