Difference in behaviour parsing numbers compared to gopkg.in/yaml.v2
jim-minter opened this issue · 2 comments
jim-minter commented
gopkg.in/yaml.v2 parses yaml integer
s into int
s and yaml float
s into float64
s, which I believe is correct.
github.com/ghodss/yaml parses both into float64
s, which is a difference in behaviour, and which I believe is wrong.
jim-minter commented
Here's a test case:
package main
import (
"fmt"
ghodssyaml "github.com/ghodss/yaml"
gopkgyaml "gopkg.in/yaml.v2"
)
const yaml = "float64: 10.0\nint: 10"
func main() {
{
var m map[string]interface{}
err := gopkgyaml.Unmarshal([]byte(yaml), &m)
if err != nil {
panic(err)
}
fmt.Printf("gopkg.in/yaml.v2: float64: %T\n", m["float64"])
fmt.Printf("gopkg.in/yaml.v2: int: %T\n", m["int"])
}
{
var m map[string]interface{}
err := ghodssyaml.Unmarshal([]byte(yaml), &m)
if err != nil {
panic(err)
}
fmt.Printf("github.com/ghodss/yaml: float64: %T\n", m["float64"])
fmt.Printf("github.com/ghodss/yaml: int: %T\n", m["int"])
}
}
The output is:
gopkg.in/yaml.v2: float64: float64
gopkg.in/yaml.v2: int: int
github.com/ghodss/yaml: float64: float64
github.com/ghodss/yaml: int: float64
I would have expected to see:
github.com/ghodss/yaml: int: int
jim-minter commented
Bah, duplicate of #25