Description

When I was writing the ShouldBindBodyWith shortcut, I tested that YAML would parse JSON BODY content, which should not be expected

How to reproduce

func TestYAMLBindingBindBodyJSON(t *testing.T) {
    var s struct {
        Foo string `yaml:"foo"`
    }
    err := yamlBinding{}.BindBody([]byte(`{"foo":"FOO"}`), &s)
    require.Error(t, err)
    assert.Equal(t, "", s.Foo)
}

Expectations

=== RUN   TestYAMLBindingBindBodyJSON
--- PASS: TestYAMLBindingBindBodyJSON (0.00s)
PASS

Actual result

=== RUN   TestYAMLBindingBindBodyJSON
    yaml_test.go:27: 
                Error Trace:    /Users/wenxingzhan/GolandProjects/gin/binding/yaml_test.go:27
                Error:          An error is expected but got nil.
                Test:           TestYAMLBindingBindBodyJSON
--- FAIL: TestYAMLBindingBindBodyJSON (0.00s)
FAIL

Environment

  • go version: go1.21.3 darwin/amd64
  • gin version (or commit ref): ecdbbbe9483dd12222f2085f717a2c7cb5ac55fe
  • operating system: mac os 14.3.1 (23D60)

Comment From: RedCrazyGhost

I looked it up, and Red Hat says that YAML is a superset of JSON, and all the data can be parsed in JSON format.