From 0c777a4967241642ed3fdfa0fc720116a030d78a Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 5 Jan 2021 13:21:33 +1100 Subject: [PATCH] Unwrap node in get tag to return proper tag at root level --- pkg/yqlib/operator_tag.go | 2 +- pkg/yqlib/operator_tag_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/operator_tag.go b/pkg/yqlib/operator_tag.go index 8b9c515b..3a4037ec 100644 --- a/pkg/yqlib/operator_tag.go +++ b/pkg/yqlib/operator_tag.go @@ -42,7 +42,7 @@ func GetTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *Pa for el := matchingNodes.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - node := &yaml.Node{Kind: yaml.ScalarNode, Value: candidate.Node.Tag, Tag: "!!str"} + node := &yaml.Node{Kind: yaml.ScalarNode, Value: UnwrapDoc(candidate.Node).Tag, Tag: "!!str"} lengthCand := &CandidateNode{Node: node, Document: candidate.Document, Path: candidate.Path} results.PushBack(lengthCand) } diff --git a/pkg/yqlib/operator_tag_test.go b/pkg/yqlib/operator_tag_test.go index e918c73f..df47335b 100644 --- a/pkg/yqlib/operator_tag_test.go +++ b/pkg/yqlib/operator_tag_test.go @@ -18,6 +18,14 @@ var tagOperatorScenarios = []expressionScenario{ "D0, P[f], (!!str)::'!!seq'\n", }, }, + { + skipDoc: true, + document: `{a: cat, b: 5, c: 3.2, e: true, f: []}`, + expression: `tag`, + expected: []string{ + "D0, P[], (!!str)::'!!map'\n", + }, + }, { description: "Convert numbers to strings", document: `{a: cat, b: 5, c: 3.2, e: true}`,