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

go-yaml v1.13.7 panic on the the input JSON string for the map slice type. #519

Closed
Peefy opened this issue Nov 11, 2024 · 3 comments · Fixed by #523
Closed

go-yaml v1.13.7 panic on the the input JSON string for the map slice type. #519

Peefy opened this issue Nov 11, 2024 · 3 comments · Fixed by #523
Labels
bug Something isn't working

Comments

@Peefy
Copy link

Peefy commented Nov 11, 2024

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

Please provide a minimum yaml content that can be reproduced.
We are more than happy to use Go Playground

Use the go 1.23 and github.com/goccy/go-yaml v1.13.7 to run the following test, it will panic with the error message but github.com/goccy/go-yaml v1.13.4, v1.13.5 and v1.13.6 work fine

func TestPanicJsonYamlMapSlice(t *testing.T) {
	code := `
{
	"apiVersion": "apps/v1",
	"kind": "Deployment",
	"metadata": {
		"name": "nginx-deployment",
		"labels": {
			"app": "nginx"
		}
	},
	"spec": {
		"replicas": 3,
		"selector": {
			"matchLabels": {
				"app": "nginx"
			}
		},
		"template": {
			"metadata": {
				"labels": {
					"app": "nginx"
				}
			},
			"spec": {
				"containers": [
					{
						"name": "nginx-container",
						"image": "nginx:latest",
						"ports": [
							{
								"containerPort": 80
							}
						]
					}
				]
			}
		}
	}
}	
`
	yamlData := &yaml.MapSlice{}
	if err := yaml.UnmarshalWithOptions([]byte(code), yamlData, yaml.UseOrderedMap(), yaml.UseJSONUnmarshaler()); err != nil {
		panic(err)
	}
}

The error message is

panic: [10:3] value is not allowed in this context
           7 |          "labels": {
           8 |                  "app": "nginx"
           9 |          }
        > 10 |  },
                 ^
          11 |  "spec": {
          12 |          "replicas": 3,
          13 |          "selector": { [recovered]
        panic: [10:3] value is not allowed in this context
           7 |          "labels": {
           8 |                  "app": "nginx"
           9 |          }
        > 10 |  },
                 ^
          11 |  "spec": {
          12 |          "replicas": 3,
          13 |          "selector": {

Expected behavior
A clear and concise description of what you expected to happen.

Test passed

Screenshots
If applicable, add screenshots to help explain your problem.

Version Variables

  • Go version: [e.g. 1.21 ] 1.23
  • go-yaml's Version: [e.g. v1.11.1 ] v1.13.7

Additional context
Add any other context about the problem here.

@yxxhero
Copy link

yxxhero commented Nov 11, 2024

@goccy
Copy link
Owner

goccy commented Nov 12, 2024

Thank you for your reporting! I'll fix this problem today

@goccy
Copy link
Owner

goccy commented Nov 12, 2024

I've fixed this problem with v1.13.8 . Please confirm it 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants