Skip to content

YAML BindBody should not parse JSON content #3862

@RedCrazyGhost

Description

@RedCrazyGhost

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): ecdbbbe
  • operating system: mac os 14.3.1 (23D60)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions