Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tag with flow sequence #618

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading