From 6b33533f9edcdda3b922567ddb3f73a486f8d278 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 9 Dec 2024 23:55:46 +0900 Subject: [PATCH] fix scalar-value-with-two-anchors (#581) --- parser/parser.go | 9 +++++++++ yaml_test_suite_test.go | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/parser/parser.go b/parser/parser.go index 959e366..08f9dfe 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -211,6 +211,9 @@ func (p *parser) parseToken(ctx *context, tk *Token) (ast.Node, error) { if err != nil { return nil, err } + if _, ok := value.(*ast.AnchorNode); ok { + return nil, errors.ErrSyntax("anchors cannot be used consecutively", value.GetToken()) + } anchor.Value = value return anchor, nil case TokenGroupAlias: @@ -283,6 +286,9 @@ func (p *parser) parseScalarValue(ctx *context, tk *Token) (ast.ScalarNode, erro if err != nil { return nil, err } + if _, ok := value.(*ast.AnchorNode); ok { + return nil, errors.ErrSyntax("anchors cannot be used consecutively", value.GetToken()) + } anchor.Value = value return anchor, nil case TokenGroupAlias: @@ -797,6 +803,9 @@ func (p *parser) parseAnchor(ctx *context, g *TokenGroup) (*ast.AnchorNode, erro if err != nil { return nil, err } + if _, ok := value.(*ast.AnchorNode); ok { + return nil, errors.ErrSyntax("anchors cannot be used consecutively", value.GetToken()) + } anchor.Value = value return anchor, nil } diff --git a/yaml_test_suite_test.go b/yaml_test_suite_test.go index 73cb459..fbd1525 100644 --- a/yaml_test_suite_test.go +++ b/yaml_test_suite_test.go @@ -53,7 +53,6 @@ var failureTestNames = []string{ "plain-dashes-in-flow-sequence", "question-mark-edge-cases/00", // no json. "question-mark-edge-cases/01", // no json. - "scalar-value-with-two-anchors", // pass yamlv3. "single-character-streams/01", // no json. "single-pair-implicit-entries", // no json. "spec-example-2-11-mapping-between-sequences", // no json.