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

Failed to unmarshal nested YAML into a map #267

Closed
franchb opened this issue Nov 18, 2021 · 3 comments · Fixed by #530
Closed

Failed to unmarshal nested YAML into a map #267

franchb opened this issue Nov 18, 2021 · 3 comments · Fixed by #530
Labels
bug Something isn't working parser

Comments

@franchb
Copy link

franchb commented Nov 18, 2021

Trying to unmarshal a nested YAML into a map[string]interface{} fails. If the order of the path and type keys changes this test will pass.

package main

import (
	"fmt"

	"github.com/goccy/go-yaml"
)

const good = `
a:
  - name: foo
    value:
      path: /var/log/syslog
      type: x
`

const bad = `
a:
  - name: foo
    value:
      type:	x
      path: /var/log/syslog
`

func main() {
	var goodMap map[interface{}]interface{}
	if err := yaml.Unmarshal([]byte(good), &goodMap); err != nil {
		panic("good map fails" + err.Error())
	}
	var badMap map[interface{}]interface{}
	if err := yaml.Unmarshal([]byte(bad), &badMap); err != nil {
		panic("bad map fails" + err.Error())
	}
	fmt.Println("OK")
}

want: OK

got:

panic: bad map fails[5:7] unexpected key name
   2 | a:
   3 |   - name: foo
   4 |     value:
>  5 |       type:	x
   6 |       path: /var/log/syslog
             ^
@goccy
Copy link
Owner

goccy commented Nov 18, 2021

To be precise, it seems to be caused by the tab character (\t) immediately after type:.

@ilteoood
Copy link

@goccy

There's also an unexpected behaviour if I try to parse a structure like this:

`
customer:
    first_name:   Dorothy
    family_name:  Gale
`

Where the keys of the object are indented using the Tab. It seems that the library can't recognize customer as an object.

@goccy goccy added bug Something isn't working parser labels Nov 12, 2024
@goccy
Copy link
Owner

goccy commented Nov 12, 2024

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

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

Successfully merging a pull request may close this issue.

3 participants