mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 14:25:38 +00:00
Fix nested inline YAML merge explode (#2699)
Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com>
This commit is contained in:
parent
702dd16048
commit
722c9aa16c
@ -170,6 +170,10 @@ func fixedReconstructAliasedMap(node *CandidateNode) error {
|
|||||||
if mergeNodeSeq.Kind == AliasNode {
|
if mergeNodeSeq.Kind == AliasNode {
|
||||||
mergeNodeSeq = mergeNodeSeq.Alias
|
mergeNodeSeq = mergeNodeSeq.Alias
|
||||||
}
|
}
|
||||||
|
mergeNodeSeq = mergeNodeSeq.Copy()
|
||||||
|
if err := explodeNode(mergeNodeSeq, Context{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if mergeNodeSeq.Kind != MappingNode {
|
if mergeNodeSeq.Kind != MappingNode {
|
||||||
return fmt.Errorf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v", mergeNodeSeq.Tag)
|
return fmt.Errorf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v", mergeNodeSeq.Tag)
|
||||||
}
|
}
|
||||||
@ -179,12 +183,7 @@ func fixedReconstructAliasedMap(node *CandidateNode) error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for _, item := range itemsToAdd {
|
for _, item := range itemsToAdd {
|
||||||
// copy to ensure exploding doesn't modify the original node
|
newContent = append(newContent, item.Copy())
|
||||||
itemCopy := item.Copy()
|
|
||||||
if err := explodeNode(itemCopy, Context{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
newContent = append(newContent, itemCopy)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -198,6 +198,15 @@ var fixedAnchorOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!map)::{a: 42}\n",
|
"D0, P[], (!!map)::{a: 42}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "Nested merge anchor with inline map",
|
||||||
|
document: `{<<: {<<: {a: 42}}}`,
|
||||||
|
expression: `explode(.)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: 42}\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
description: "Merge anchor with sequence with inline map",
|
description: "Merge anchor with sequence with inline map",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user