Skip to content

Commit

Permalink
add validation for sequence value
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Dec 10, 2024
1 parent 4e14b77 commit 3989c51
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,13 +790,13 @@ func (p *parser) parseMapValue(ctx *context, key ast.MapKeyNode, colonTk *Token)
if err != nil {
return nil, err
}
if err := p.validateAnchorValueInMap(value, keyCol); err != nil {
if err := p.validateAnchorValueInMapOrSeq(value, keyCol); err != nil {
return nil, err
}
return value, nil
}

func (p *parser) validateAnchorValueInMap(value ast.Node, keyCol int) error {
func (p *parser) validateAnchorValueInMapOrSeq(value ast.Node, col int) error {
anchor, ok := value.(*ast.AnchorNode)
if !ok {
return nil
Expand All @@ -811,12 +811,17 @@ func (p *parser) validateAnchorValueInMap(value ast.Node, keyCol int) error {
if anchorTk.Position.Line == tagTk.Position.Line {
// key:
// &anchor !!tag
//
// - &anchor !!tag
return nil
}

if tagTk.Position.Column <= keyCol {
if tagTk.Position.Column <= col {
// key: &anchor
// !!tag
//
// - &anchor
// !!tag
return errors.ErrSyntax("tag is not allowed in this context", tagTk)
}
return nil
Expand Down Expand Up @@ -1159,6 +1164,9 @@ func (p *parser) parseSequenceValue(ctx *context, seqTk *Token) (ast.Node, error
if err != nil {
return nil, err
}
if err := p.validateAnchorValueInMapOrSeq(value, seqCol); err != nil {
return nil, err
}
return value, nil
}

Expand Down

0 comments on commit 3989c51

Please sign in to comment.