Skip to content

Commit ef4b9eb

Browse files
committed
fix implicit null value before collect entry
1 parent 950afad commit ef4b9eb

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

decode_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ func TestDecoder(t *testing.T) {
977977
{
978978
"{}", struct{}{},
979979
},
980+
{
981+
"{a: , b: c}",
982+
map[string]any{"a": nil, "b": "c"},
983+
},
980984
{
981985
"v: /a/{b}",
982986
map[string]string{"v": "/a/{b}"},

parser/parser.go

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken
154154
nullToken := p.createNullToken(colonToken)
155155
ctx.insertToken(ctx.idx, nullToken)
156156
return ast.Null(nullToken), nil
157+
} else if tk.Type == token.CollectEntryType {
158+
// implicit null value.
159+
return ast.Null(tk), nil
157160
}
158161
var comment *ast.CommentGroupNode
159162
if tk.Type == token.CommentType {

parser/parser_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func TestParser(t *testing.T) {
8787
"a_ok: \r bc: 2\r",
8888
"a_mk: \n bd: 3\n",
8989
"a: :a",
90+
"{a: , b: c}",
9091
}
9192
for _, src := range sources {
9293
if _, err := parser.Parse(lexer.Tokenize(src), 0); err != nil {

0 commit comments

Comments
 (0)