Skip to content

Commit 817287e

Browse files
committed
Check merge alias is a map #1425
1 parent c5994a8 commit 817287e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pkg/yqlib/operator_anchors_aliases.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package yqlib
22

33
import (
44
"container/list"
5+
"fmt"
56

67
yaml "gopkg.in/yaml.v3"
78
)
@@ -244,6 +245,9 @@ func applyAlias(node *yaml.Node, alias *yaml.Node, aliasIndex int, newContent Co
244245
if alias == nil {
245246
return nil
246247
}
248+
if alias.Kind != yaml.MappingNode {
249+
return fmt.Errorf("merge anchor only supports maps, got %v instead", alias.Tag)
250+
}
247251
for index := 0; index < len(alias.Content); index = index + 2 {
248252
keyNode := alias.Content[index]
249253
log.Debugf("applying alias key %v", keyNode.Value)

pkg/yqlib/operator_anchors_aliases_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ thingTwo:
3636
`
3737

3838
var anchorOperatorScenarios = []expressionScenario{
39+
{
40+
skipDoc: true,
41+
description: "merge anchor not map",
42+
document: "a: &a\n - 0\nc:\n <<: [*a]\n",
43+
expectedError: "merge anchor only supports maps, got !!seq instead",
44+
expression: "explode(.)",
45+
},
3946
{
4047
description: "Merge one map",
4148
subdescription: "see https://yaml.org/type/merge.html",

0 commit comments

Comments
 (0)