go-yaml / yaml

YAML support for the Go language.
Other
6.82k stars 1.04k forks source link

String key resolving to bool because of type hint. #368

Open Dennor opened 6 years ago

Dennor commented 6 years ago

Not sure if this works as intended but n and y string keys resolve to bool

For example:

package main
import (
    "fmt"
    "github.com/go-yaml/yaml"
)

func main() {
    b := []byte(`keys:
  - alg: RSA256
    kid: somersakid
    kty: RSA
    use: sig
    n: AQAB
    e: AQAB
  - alg: ES256
    kid: someeckid
    kty: EC
    use: sig
    crv: P-256
    x: AQAB
    y: AQAB
`)
    m := make(map[string]interface{})
    if err := yaml.Unmarshal(b, m); err != nil {
        panic(err.Error())
    }
    fmt.Printf("%v\n", m)
}

Results with map[keys:[map[use:sig false:AQAB e:AQAB alg:RSA256 kid:somersakid kty:RSA] map[kid:someeckid kty:EC use:sig crv:P-256 x:AQAB true:AQAB alg:ES256]]]

Not a major issue as I can just wrap n and y in quotes, but it does seem weird.

k80w commented 6 years ago

Having this as well. A setting for the default type for keys would be useful.

dlouzan commented 5 years ago

I have also just discovered this on our codebase while converting some OpenAPI 3 specs.

This seems a duplicate of #214, the YAML spec 1.2 actually solves it.