Check merge alias is a map #1425

This commit is contained in:
Mike Farah 2022-11-11 14:53:45 +11:00
parent c5994a8b28
commit 817287ec90
2 changed files with 11 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package yqlib
import (
"container/list"
"fmt"
yaml "gopkg.in/yaml.v3"
)
@ -244,6 +245,9 @@ func applyAlias(node *yaml.Node, alias *yaml.Node, aliasIndex int, newContent Co
if alias == 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 {
keyNode := alias.Content[index]
log.Debugf("applying alias key %v", keyNode.Value)

View File

@ -36,6 +36,13 @@ thingTwo:
`
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",
subdescription: "see https://yaml.org/type/merge.html",