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 parsing of invalid map key #520

Merged
merged 1 commit into from
Nov 11, 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
2 changes: 2 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ func (p *parser) createNodeFromToken(ctx *context, tk *token.Token) (ast.Node, e
return p.parseTag(ctx)
case token.LiteralType, token.FoldedType:
return p.parseLiteral(ctx)
case token.MappingValueType:
return nil, errors.ErrSyntax("found an invalid key for this map", tk)
}
return nil, nil
}
Expand Down
16 changes: 16 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,22 @@ a:
"key: [`val]",
"\n[1:7] found invalid token\n> 1 | key: [`val]\n ^\n",
},
{
`{a: b}: v`,
`
[1:7] found an invalid key for this map
> 1 | {a: b}: v
^
`,
},
{
`[a]: v`,
`
[1:4] found an invalid key for this map
> 1 | [a]: v
^
`,
},
}
for _, test := range tests {
t.Run(test.source, func(t *testing.T) {
Expand Down
Loading