Repository: goccy/go-yaml
Pull request #618 (2025-01-16 10:19:50)

Fix tag with flow sequence
fix https://github.com/goccy/go-yaml/issues/617

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/618?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 77.34%. Comparing base [(`1c32d14`)](https://app.codecov.io/gh/goccy/go-yaml/commit/1c32d1422e46313939211a5cf895f7a438786fc6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) to head [(`b12574b`)](https://app.codecov.io/gh/goccy/go-yaml/commit/b12574bd54285c146ff277926d095d29125cdfe7?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     #618      +/-   ##
==========================================
+ Coverage   77.32%   77.34%   +0.02%     
==========================================
  Files          22       22              
  Lines        7871     7880       +9     
==========================================
+ Hits         6086     6095       +9     
  Misses       1368     1368              
  Partials      417      417              
```

</details>

Patch:
diff --git a/ast/ast.go b/ast/ast.go
index 50428a2..357ca81 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -1939,6 +1939,14 @@ func (n *TagNode) IsMergeKey() bool {
 	return key.IsMergeKey()
 }
 
+func (n *TagNode) ArrayRange() *ArrayNodeIter {
+	arr, ok := n.Value.(ArrayNode)
+	if !ok {
+		return nil
+	}
+	return arr.ArrayRange()
+}
+
 // CommentNode type of comment node
 type CommentNode struct {
 	*BaseNode
diff --git a/parser/token.go b/parser/token.go
index 060db65..b72de4f 100644
--- a/parser/token.go
+++ b/parser/token.go
@@ -426,6 +426,10 @@ func createScalarTagTokenGroups(tokens []*Token) ([]*Token, error) {
 				ret = append(ret, tk)
 				continue
 			}
+			if isFlowType(tokens[i+1]) {
+				ret = append(ret, tk)
+				continue
+			}
 			ret = append(ret, &Token{
 				Group: &TokenGroup{
 					Type:   TokenGroupScalarTag,
@@ -731,3 +735,11 @@ func isNotMapKeyType(tk *Token) bool {
 		typ == token.SequenceEntryType ||
 		typ == token.SequenceEndType
 }
+
+func isFlowType(tk *Token) bool {
+	typ := tk.Type()
+	return typ == token.MappingStartType ||
+		typ == token.MappingEndType ||
+		typ == token.SequenceStartType ||
+		typ == token.SequenceEntryType
+}


Test patch:
diff --git a/decode_test.go b/decode_test.go
index f5308cf..6b99879 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -3175,3 +3175,18 @@ func TestDecodeError(t *testing.T) {
 		})
 	}
 }
+
+func TestIssue617(t *testing.T) {
+	data := `
+a: !Not [!Equals [!Ref foo, 'bar']]
+`
+	var v map[string][]any
+	if err := yaml.Unmarshal([]byte(data), &v); err != nil {
+		t.Fatal(err)
+	}
+	if !reflect.DeepEqual(v, map[string][]any{
+		"a": {[]any{"foo", "bar"}},
+	}) {
+		t.Fatalf("found unexpected value: %v", v)
+	}
+}