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

YAML BindBody should not parse JSON content #3862

Closed
RedCrazyGhost opened this issue Mar 2, 2024 · 1 comment
Closed

YAML BindBody should not parse JSON content #3862

RedCrazyGhost opened this issue Mar 2, 2024 · 1 comment

Comments

@RedCrazyGhost
Copy link
Contributor

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)
@RedCrazyGhost
Copy link
Contributor Author

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.

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