Skip to content

Commit

Permalink
fix implicit null value before collect entry (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy authored Oct 30, 2024
1 parent 950afad commit af5147b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ func TestDecoder(t *testing.T) {
{
"{}", struct{}{},
},
{
"{a: , b: c}",
map[string]any{"a": nil, "b": "c"},
},
{
"v: /a/{b}",
map[string]string{"v": "/a/{b}"},
Expand Down
3 changes: 3 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken
nullToken := p.createNullToken(colonToken)
ctx.insertToken(ctx.idx, nullToken)
return ast.Null(nullToken), nil
} else if tk.Type == token.CollectEntryType {
// implicit null value.
return ast.Null(tk), nil
}
var comment *ast.CommentGroupNode
if tk.Type == token.CommentType {
Expand Down
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestParser(t *testing.T) {
"a_ok: \r bc: 2\r",
"a_mk: \n bd: 3\n",
"a: :a",
"{a: , b: c}",
}
for _, src := range sources {
if _, err := parser.Parse(lexer.Tokenize(src), 0); err != nil {
Expand Down

0 comments on commit af5147b

Please sign in to comment.