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
{{ message }}
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Starting a numeric sequence with zero indicates an octal number. So 01234567 == 342391 (base 10). Numeric sequences that start with zero and contain numbers higher than 7 are invalid integers and should be parsed as strings even when they do not have quotes around them.
key: 01182252
01182252 is not a valid octal integer and should be treated as a string. go-yaml attempts to parse the numeric sequence as an integer and this is incorrect.
Several yaml validators and other language yaml packages handle this case correctly such as the Python ruamel package and on line parsers http://yaml-online-parser.appspot.com/
package main
import (
"fmt"
"gopkg.in/v2/yaml"
)
var a = make(map[string]interface{})
func main() {
data := []byte(`key: 01234567`)
err := yaml.Unmarshal(data, a)
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Printf("%v\n", a["key"])
// This value is surrounded by quotes.
data = []byte(`key: "01182252"`)
err = yaml.Unmarshal(data, a)
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Printf("%v\n", a["key"])
// This value is not a valid octal integer therefore a string.
data = []byte(`key: 01182252`)
err = yaml.Unmarshal(data, a)
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Printf("%v\n", a["key"])
}