diff --git a/decode_test.go b/decode_test.go index 4d2c999b..50d633f7 100644 --- a/decode_test.go +++ b/decode_test.go @@ -939,6 +939,18 @@ c: d "c": "d", }, }, + { + `--- +a: +b: +c: +`, + map[string]interface{}{ + "a": nil, + "b": nil, + "c": nil, + }, + }, // Multi bytes { diff --git a/parser/parser.go b/parser/parser.go index 56d7b9bc..78d9fa3a 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -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: + // 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: + // in this case, + // ---- + // key: + // next nullToken := p.createNullToken(colonToken) ctx.insertToken(ctx.idx, nullToken) return ast.Null(nullToken), nil diff --git a/parser/parser_test.go b/parser/parser_test.go index a6e7546e..c41766e2 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -183,7 +183,7 @@ a: 0 - 1 - a: b: c d: e -- f: +- f: null g: h `, }, @@ -223,7 +223,7 @@ a: - a : b: c `, ` -- a: +- a: null b: c `, },