Fixed panic for syntax error when creating a map #2423

This commit is contained in:
Mike Farah 2025-07-16 15:35:12 +10:00
parent 8e731ac13c
commit 55daf6d93c
2 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package yqlib
import (
"container/list"
"fmt"
)
/*
@ -34,6 +35,9 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, _ *Exp
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidateNode := el.Value.(*CandidateNode)
if len(candidateNode.Content) < len(first.Content) {
return Context{}, fmt.Errorf("CollectObject: mismatching node sizes; are you creating a map with mismatching key value pairs?")
}
for i := 0; i < len(first.Content); i++ {
log.Debugf("rotate[%v] = %v", i, NodeToString(candidateNode.Content[i]))

View File

@ -12,6 +12,11 @@ var collectObjectOperatorScenarios = []expressionScenario{
"D0, P[name], (!!str)::mike\n",
},
},
{
skipDoc: true,
expression: `{"c": "a", "b", "d"}`,
expectedError: "CollectObject: mismatching node sizes; are you creating a map with mismatching key value pairs?",
},
{
skipDoc: true,
expression: `{"person": {"names": ["mike"]}} | .person.names[0]`,