Repository: goccy/go-yaml
Pull request #581 (2024-12-09 14:48:47)

Fix scalar-value-with-two-anchors
SSIA

codecov-commenter: :warning: Please install the !['codecov app svg image'](https://github.com/codecov/engineering-team/assets/152432831/e90313f4-9d3a-4b63-8b54-cfe14e7ec20d) to ensure uploads and comments are reliably processed by Codecov.

## [Codecov](https://app.codecov.io/gh/goccy/go-yaml/pull/581?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) Report
Attention: Patch coverage is `33.33333%` with `6 lines` in your changes missing coverage. Please review.
> Project coverage is 77.38%. Comparing base [(`6100d5f`)](https://app.codecov.io/gh/goccy/go-yaml/commit/6100d5f35728c4a023a28788434158754813f7e2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) to head [(`d4be04a`)](https://app.codecov.io/gh/goccy/go-yaml/commit/d4be04a0d684e4825b6d3c684c7a264607bb64ad?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima).

:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #581      +/-   ##
==========================================
- Coverage   77.43%   77.38%   -0.06%     
==========================================
  Files          21       21              
  Lines        7654     7663       +9     
==========================================
+ Hits         5927     5930       +3     
- Misses       1321     1325       +4     
- Partials      406      408       +2     
```

</details>

Patch:
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
 }


Test patch:
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.