diff --git a/pkg/yqlib/operator_add_test.go b/pkg/yqlib/operator_add_test.go index 93f0bb89..1c6b144e 100644 --- a/pkg/yqlib/operator_add_test.go +++ b/pkg/yqlib/operator_add_test.go @@ -310,6 +310,13 @@ var addOperatorScenarios = []expressionScenario{ "D0, P[], (!!map)::a: !cat Saturday, 15-Dec-01 at 6:00AM GMT\n", }, }, + { + skipDoc: true, + description: "empty add shouldn't add", + document: `[]`, + expression: `.[] | (.a + "cat")`, + expected: []string{}, + }, { skipDoc: true, description: "Add to empty", diff --git a/pkg/yqlib/operators.go b/pkg/yqlib/operators.go index 994a8767..293ac4a3 100644 --- a/pkg/yqlib/operators.go +++ b/pkg/yqlib/operators.go @@ -118,7 +118,7 @@ func doCrossFunc(d *dataTreeNavigator, context Context, expressionNode *Expressi } log.Debugf("crossFunction LHS len: %v", lhs.MatchingNodes.Len()) - if prefs.CalcWhenEmpty && lhs.MatchingNodes.Len() == 0 { + if prefs.CalcWhenEmpty && context.MatchingNodes.Len() > 0 && lhs.MatchingNodes.Len() == 0 { err := resultsForRHS(d, context, nil, prefs, expressionNode.RHS, results) if err != nil { return Context{}, err diff --git a/project-words.txt b/project-words.txt index 808da214..f69c3417 100644 --- a/project-words.txt +++ b/project-words.txt @@ -255,4 +255,5 @@ zabbix tonumber noyaml nolint -shortfile \ No newline at end of file +shortfile +Unmarshalling \ No newline at end of file