mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 06:10:36 +00:00
Check merge alias is a map #1425
This commit is contained in:
parent
c5994a8b28
commit
817287ec90
@ -2,6 +2,7 @@ package yqlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -244,6 +245,9 @@ func applyAlias(node *yaml.Node, alias *yaml.Node, aliasIndex int, newContent Co
|
|||||||
if alias == nil {
|
if alias == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if alias.Kind != yaml.MappingNode {
|
||||||
|
return fmt.Errorf("merge anchor only supports maps, got %v instead", alias.Tag)
|
||||||
|
}
|
||||||
for index := 0; index < len(alias.Content); index = index + 2 {
|
for index := 0; index < len(alias.Content); index = index + 2 {
|
||||||
keyNode := alias.Content[index]
|
keyNode := alias.Content[index]
|
||||||
log.Debugf("applying alias key %v", keyNode.Value)
|
log.Debugf("applying alias key %v", keyNode.Value)
|
||||||
|
|||||||
@ -36,6 +36,13 @@ thingTwo:
|
|||||||
`
|
`
|
||||||
|
|
||||||
var anchorOperatorScenarios = []expressionScenario{
|
var anchorOperatorScenarios = []expressionScenario{
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "merge anchor not map",
|
||||||
|
document: "a: &a\n - 0\nc:\n <<: [*a]\n",
|
||||||
|
expectedError: "merge anchor only supports maps, got !!seq instead",
|
||||||
|
expression: "explode(.)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Merge one map",
|
description: "Merge one map",
|
||||||
subdescription: "see https://yaml.org/type/merge.html",
|
subdescription: "see https://yaml.org/type/merge.html",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user