Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jim-minter opened this issue Jun 13, 2018 · 2 comments
Closed

Comments

@jim-minter
Copy link

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.

@jim-minter
Copy link
Author

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
Copy link
Author

Bah, duplicate of #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant