goccy / go-yaml

YAML support for the Go language
MIT License
1.12k stars 129 forks source link

Simple quote encoded with two simple quote if ] present #444

Closed louhde closed 5 months ago

louhde commented 5 months ago

Describe the bug When a string contains simple quote and [ symbol, the simple quote is encoded with double single quote

To Reproduce

main.go

package main

import (
    "os"

    "gopkg.in/yaml.v2"
)

type Test struct {
    Name string `yaml:"name"`
    Test string `yaml:"test"`
}

func main() {
    test := Test{
        Name: "NAME",
        Test: "['value', 'value2']",
    }

    out, err := yaml.Marshal(test)
    if err != nil {
        panic(err)
    }
    err = os.WriteFile("test.yaml", out, 0644)
    if err != nil {
        panic(err)
    }
}

test.yaml

name: NAME
test: '[''value'', ''value2'']'

Expected behavior

test.yaml

name: NAME
test: "['value', 'value2']"

Version Variables

louhde commented 5 months ago

I just see that there are two differents go-yaml package the official one and yours, sorry the issue does not concern your package. I close