Skip to content

Commit

Permalink
Fix tag with flow sequence (#618)
Browse files Browse the repository at this point in the history
* fix tag with flow sequence

* fix lint error
  • Loading branch information
goccy authored Jan 16, 2025
1 parent 1c32d14 commit 4260634
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
12 changes: 12 additions & 0 deletions parser/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

0 comments on commit 4260634

Please sign in to comment.