You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using the yaml.MarshalWithOptions function combined with the yaml.WithComment option if there is an empty array on the same line as the key this will result in the value being written in the comment instead of as a value.
To Reproduce
The following snippet can be used in Go Playground (I would provide a link but it was failing to generate one for me):
package main
import (
"fmt""github.com/goccy/go-yaml"
)
varinput []byte= []byte(`type: defaultdescription: test dataproblem: []`)
funcmain() {
varfmap[string]interface{}
varerrerroriferr=yaml.Unmarshal(input, &f); err!=nil {
panic(err)
}
varout []byteout, err=yaml.MarshalWithOptions(f, yaml.WithComment(
yaml.CommentMap{
"$.description": []*yaml.Comment{yaml.LineComment("This line has no problems writing the comment")},
"$.problem": []*yaml.Comment{yaml.LineComment("The problem is on this line of output")},
},
))
fmt.Println(string(out))
}
Expected behavior
I would expect valid YAML to be written out and the value of problem would come before the comment character.
e.g.:
description: test data #This line has no problems writing the commentproblem: [] #The problem is on this line of outputtype: default
Screenshots
This is the output I'm receiving when using the provided snippet:
description: test data #This line has no problems writing the commentproblem #The problem is on this line of output: []type: default
Version Variables
Go version: 1.21.0
go-yaml's Version: v1.11.2
Additional context
If I switch from MarshalWithOptions -> Marshal and forgo the comments then the output is valid YAML. I have not done any testing with other option types.
The text was updated successfully, but these errors were encountered:
Describe the bug
When using the
yaml.MarshalWithOptions
function combined with theyaml.WithComment
option if there is an empty array on the same line as the key this will result in the value being written in the comment instead of as a value.To Reproduce
The following snippet can be used in Go Playground (I would provide a link but it was failing to generate one for me):
Expected behavior
I would expect valid YAML to be written out and the value of
problem
would come before the comment character.e.g.:
Screenshots
This is the output I'm receiving when using the provided snippet:
Version Variables
Additional context
If I switch from
MarshalWithOptions
->Marshal
and forgo the comments then the output is valid YAML. I have not done any testing with other option types.The text was updated successfully, but these errors were encountered: