Skip to content

Commit

Permalink
fix invalid map-value
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Nov 30, 2024
1 parent 8c8237b commit bc98813
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,15 @@ func (p *parser) parseMapValue(ctx *context, key ast.MapKeyNode, colonTk *Token)
keyCol := key.GetToken().Position.Column
keyLine := key.GetToken().Position.Line

if tk.Column() != keyCol && tk.Line() == keyLine && (tk.GroupType() == TokenGroupMapKey || tk.GroupType() == TokenGroupMapKeyValue) {
// a: b:
// ^
//
// a: b: c
// ^
return nil, errors.ErrSyntax("mapping value is not allowed in this context", tk.RawToken())
}

if tk.Column() == keyCol && p.isMapToken(tk) {
// in this case,
// ----
Expand Down
4 changes: 4 additions & 0 deletions parser/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ func createDocumentTokens(tokens []*Token) ([]*Token, error) {
}

func isScalarType(tk *Token) bool {
switch tk.GroupType() {
case TokenGroupMapKey, TokenGroupMapKeyValue:
return false
}
typ := tk.Type()
return typ == token.AnchorType ||
typ == token.AliasType ||
Expand Down
3 changes: 1 addition & 2 deletions yaml_test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ var failureTestNames = []string{
"anchors-on-empty-scalars", // no json.
"aliases-in-flow-objects", // no json.
"aliases-in-explicit-block-mapping", // no json.
"bare-document-after-document-end-marker",
"block-mapping-with-missing-keys", // no json.
"block-mapping-with-missing-keys", // no json.
"block-mapping-with-missing-values",
"block-mapping-with-multiline-scalars",
"block-scalar-with-more-spaces-than-first-content-line",
Expand Down

0 comments on commit bc98813

Please sign in to comment.