Handle scalars in property files

This commit is contained in:
Mike Farah 2023-03-27 13:51:08 +11:00
parent ac5346b138
commit 1b0a62d08d
2 changed files with 13 additions and 0 deletions

View File

@ -63,6 +63,11 @@ func (pe *propertiesEncoder) PrintLeadingContent(writer io.Writer, content strin
} }
func (pe *propertiesEncoder) Encode(writer io.Writer, node *yaml.Node) error { func (pe *propertiesEncoder) Encode(writer io.Writer, node *yaml.Node) error {
if node.Kind == yaml.ScalarNode {
return writeString(writer, node.Value+"\n")
}
mapKeysToStrings(node) mapKeysToStrings(node)
p := properties.NewProperties() p := properties.NewProperties()
err := pe.doEncode(p, node, "", nil) err := pe.doEncode(p, node, "", nil)

View File

@ -162,6 +162,14 @@ var propertyScenarios = []formatScenario{
expected: "mike: ${dontExpand} this\n", expected: "mike: ${dontExpand} this\n",
scenarioType: "decode", scenarioType: "decode",
}, },
{
description: "print scalar",
skipDoc: true,
input: "mike = cat",
expression: ".mike",
expected: "cat\n",
scenarioType: "roundtrip",
},
{ {
description: "Roundtrip", description: "Roundtrip",
input: expectedPropertiesUnwrapped, input: expectedPropertiesUnwrapped,