Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid map token #504

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading