Unwrap node in get tag to return proper tag at root level

This commit is contained in:
Mike Farah 2021-01-05 13:21:33 +11:00
parent e9591e0cd5
commit 0c777a4967
2 changed files with 9 additions and 1 deletions

View File

@ -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)
}

View File

@ -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}`,