goccy / go-yaml

YAML support for the Go language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty items in block sequence incorrectly reported as error

lukemassa opened this issue · comments

Describe the bug
The following is valid yaml:

foo:
-

but the code treats this as an error:

[2:1] empty sequence entry
       1 | foo:
    >  2 | -
           ^

See: https://yaml.org/spec/1.2.2/#72-empty-nodes

To Reproduce

https://go.dev/play/p/RHQfxSlvxTK

There's even a unit test that expects an error from valid yaml: https://github.com/goccy/go-yaml/blob/master/parser/parser_test.go#L686

a:
- b: c
- 

If you feed that into https://www.yamllint.com/, https://yamlchecker.com/, gopkg.in/yaml.v2, and gopkg.in/yaml.v3, they all say that's valid yaml.

Expected behavior

An empty sequence should be treated as if it were the "zero value"

Version Variables

  • Go version: 1.21
  • go-yaml's Version: v1.11.2

Additional context
I believe this might be related to #313 and #168.