ghodss/yaml

Difference in behaviour parsing numbers compared to gopkg.in/yaml.v2

jim-minter opened this issue · 2 comments

gopkg.in/yaml.v2 parses yaml integers into ints and yaml floats into float64s, which I believe is correct.
github.com/ghodss/yaml parses both into float64s, which is a difference in behaviour, and which I believe is wrong.

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

Bah, duplicate of #25