Skip to content

Commit

Permalink
fix invalid map token (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy authored Nov 3, 2024
1 parent ab16112 commit 2e63415
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) {
ntk = p.nextNotCommentToken()
antk = p.afterNextNotCommentToken()
}
if tk := p.nextNotCommentToken(); tk != nil && tk.Position.Line > node.Start.Position.Line && tk.Position.Column > node.Start.Position.Column {
// a: b
// c <= this token is invalid.
return nil, errors.ErrSyntax("value is not allowed in this context", tk)
}
if len(node.Values) == 1 {
mapKeyCol := mvnode.Key.GetToken().Position.Column
commentTk := p.nextToken()
Expand Down
38 changes: 38 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,44 @@ b
},
{
`
a: 'b'
c: d
`,
`
[3:3] value is not allowed in this context
2 | a: 'b'
> 3 | c: d
^
`,
},
{
`
a: 'b'
- c
`,
`
[3:3] value is not allowed in this context
2 | a: 'b'
> 3 | - c
^
`,
},
{
`
a: 'b'
# comment
- c
`,
`
[4:3] value is not allowed in this context
2 | a: 'b'
3 | # comment
> 4 | - c
^
`,
},
{
`
a: 1
b
- c
Expand Down

0 comments on commit 2e63415

Please sign in to comment.