Skip to content

Commit 55daf6d

Browse files
committed
Fixed panic for syntax error when creating a map #2423
1 parent 8e731ac commit 55daf6d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/yqlib/operator_collect_object.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

78
/*
@@ -34,6 +35,9 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, _ *Exp
3435

3536
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
3637
candidateNode := el.Value.(*CandidateNode)
38+
if len(candidateNode.Content) < len(first.Content) {
39+
return Context{}, fmt.Errorf("CollectObject: mismatching node sizes; are you creating a map with mismatching key value pairs?")
40+
}
3741

3842
for i := 0; i < len(first.Content); i++ {
3943
log.Debugf("rotate[%v] = %v", i, NodeToString(candidateNode.Content[i]))

pkg/yqlib/operator_collect_object_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ var collectObjectOperatorScenarios = []expressionScenario{
1212
"D0, P[name], (!!str)::mike\n",
1313
},
1414
},
15+
{
16+
skipDoc: true,
17+
expression: `{"c": "a", "b", "d"}`,
18+
expectedError: "CollectObject: mismatching node sizes; are you creating a map with mismatching key value pairs?",
19+
},
1520
{
1621
skipDoc: true,
1722
expression: `{"person": {"names": ["mike"]}} | .person.names[0]`,

0 commit comments

Comments
 (0)