Skip to content

Commit

Permalink
Merge pull request #116 from goccy/feature/fix-empty-token-as-map-value
Browse files Browse the repository at this point in the history
Fix processing when specified empty token as map value ( 2 )
  • Loading branch information
goccy authored Jun 3, 2020
2 parents e7e6579 + 043e7bd commit f2d7291
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 12 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,18 @@ c: d
"c": "d",
},
},
{
`---
a:
b:
c:
`,
map[string]interface{}{
"a": nil,
"b": nil,
"c": nil,
},
},

// Multi bytes
{
Expand Down
15 changes: 14 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,21 @@ func (p *parser) parseMapValue(ctx *context, key ast.Node, colonToken *token.Tok
return ast.Null(nullToken), nil
}

if tk.Position.Column == key.GetToken().Position.Column && tk.Type == token.StringType {
// in this case,
// ----
// key: <value does not defined>
// next
nullToken := p.createNullToken(colonToken)
ctx.insertToken(ctx.idx, nullToken)
return ast.Null(nullToken), nil
}

if tk.Position.Column < key.GetToken().Position.Column {
// in this case, key: <value does not defined>
// in this case,
// ----
// key: <value does not defined>
// next
nullToken := p.createNullToken(colonToken)
ctx.insertToken(ctx.idx, nullToken)
return ast.Null(nullToken), nil
Expand Down
4 changes: 2 additions & 2 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ a: 0 - 1
- a:
b: c
d: e
- f:
- f: null
g: h
`,
},
Expand Down Expand Up @@ -223,7 +223,7 @@ a:
- a :
b: c
`, `
- a:
- a: null
b: c
`,
},
Expand Down

0 comments on commit f2d7291

Please sign in to comment.