Skip to content

Commit

Permalink
fix parsing of invalid map key (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy authored Nov 11, 2024
1 parent 8f36c1b commit 7e833a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit 7e833a2

Please sign in to comment.