`:` inserted as list separator if list is >= 4 items long
gabbifish opened this issue · 3 comments
gabbifish commented
Hello! We are on hiera version v0.2.0.
We are parsing a fact into a JSON output format and noticed a parsing error.
When parsing a yaml list like
myList:
- typeA: a
- typeB: b
- typeC: c
- tupeD: d
hiera will parse it as
[{"typeA":"a"},{"typeB":"b"},{"typeC":"c"}:{"tupeD":"d"}]
Note that what should have been a comma delimiter is now a :
!
We have the go code to parse from the yaml file:
var variables []string
for _, fact := range facts {
variables = append(variables, fact.String())
}
cmdOpts.Merge = "deep"
cmdOpts.Variables = variables
cmdOpts.RenderAs = formatToFormatString(format)
configOptions := map[string]px.Value{
provider.LookupKeyFunctions: types.WrapRuntime([]hieraapi.LookupKey{provider.ConfigLookupKey, provider.Environment})}
configOptions[hieraapi.HieraConfig] = types.WrapString(path.Join(directory, "hierav5.yaml"))
dest := bytes.NewBuffer(nil)
err := hiera.TryWithParent(context.TODO(), provider.MuxLookupKey, configOptions, func(c px.Context) error {
hiera.LookupAndRender(c, &cmdOpts, []string{key}, dest)
return nil
})
thallgren commented
Would it be possible for you to try the tip of the v1.0.x branch and check if the problem is still there?
thallgren commented
I added the following test to v1.0.x:
func TestLookup_fourElementSlice(t *testing.T) {
inTestdata(func() {
result, err := cli.ExecuteLookup(`--config`, `hiera.yaml`, `--render-as`, `json`, `myList`)
require.NoError(t, err)
require.Equal(t, `[{"typeA":"a"},{"typeB":"b"},{"typeC":"c"},{"tupeD":"d"}]`, strings.TrimSpace(string(result)))
})
}
with this data in hiera/common.yaml
myList:
- typeA: a
- typeB: b
- typeC: c
- tupeD: d
and the test passes.
gabbifish commented
Heh, after some grappling with the breaking changes between v0.2.0 and v1.0.x (there were quite a few!) it looks like this fix is present in v1.0.x! Thank you for adding a test to verify this!