diff --git a/decode_test.go b/decode_test.go index 2373804d..1152c609 100644 --- a/decode_test.go +++ b/decode_test.go @@ -591,6 +591,10 @@ func TestDecoder(t *testing.T) { "v:\n - A\n - B", map[string]interface{}{"v": []interface{}{"A", "B"}}, }, + { + "v:\n-", + map[string][]string{"v": []string{""}}, + }, { "v:\n - A\n - B\n - C", map[string][]string{"v": []string{"A", "B", "C"}}, diff --git a/parser/parser.go b/parser/parser.go index 13ada50f..d363421c 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -327,20 +327,23 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) { for tk.Type == token.SequenceEntryType { ctx.progress(1) // skip sequence token tk = ctx.currentToken() - if tk == nil { - return nil, errors.ErrSyntax("empty sequence entry", ctx.previousToken()) - } var comment *ast.CommentGroupNode - if tk.Type == token.CommentType { - comment = p.parseCommentOnly(ctx) - tk = ctx.currentToken() - if tk.Type == token.SequenceEntryType { - ctx.progress(1) // skip sequence token + var value ast.Node + var err error + if tk == nil { + value = &ast.NullNode{} + } else { + if tk.Type == token.CommentType { + comment = p.parseCommentOnly(ctx) + tk = ctx.currentToken() + if tk.Type == token.SequenceEntryType { + ctx.progress(1) // skip sequence token + } + } + value, err = p.parseToken(ctx.withIndex(uint(len(sequenceNode.Values))), ctx.currentToken()) + if err != nil { + return nil, errors.Wrapf(err, "failed to parse sequence") } - } - value, err := p.parseToken(ctx.withIndex(uint(len(sequenceNode.Values))), ctx.currentToken()) - if err != nil { - return nil, errors.Wrapf(err, "failed to parse sequence") } if comment != nil { comment.SetPath(ctx.withIndex(uint(len(sequenceNode.Values))).path) diff --git a/parser/parser_test.go b/parser/parser_test.go index 8d697e8c..eb1a1ecc 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -679,19 +679,6 @@ a [1:1] unterminated flow mapping > 1 | { "key": "value" ^ -`, - }, - { - ` -a: -- b: c -- `, - ` -[4:1] empty sequence entry - 2 | a: - 3 | - b: c -> 4 | - - ^ `, }, }