go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent behaviour when marshalling strings

eBerdnA opened this issue · comments

I have the following input file.

title: "2023-08-23"
title2: "A title with a colon: inside"
title3: '2023-08-23'

Using the following code I get a slightly unexpected result. I use v3.0.1 and go1.20.2 darwin/arm64 for this.

rawYaml, _ := os.ReadFile("./input.yaml")
yamlMap := make(map[string]string)
yaml.Unmarshal(rawYaml, &yamlMap)

marschalled, _ := yaml.Marshal(yamlMap)
fmt.Println(string(marschalled))

The output is the following.

title: "2023-08-23"
title2: 'A title with a colon: inside'
title3: "2023-08-23"

My questions is, why is title still encapsulated in double quotes but title2 is only encapsulated with single quotes and title3 even gets switched over. For me this behaviour looks quite confusing and inconsistent.