From 2c2487c0bdc25279ab434e7a56c760dde336b191 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 9 May 2025 15:29:44 +1000 Subject: [PATCH] Fixing Regression in #2353, #2359, #2325 --- pkg/yqlib/operator_add_test.go | 7 +++++++ pkg/yqlib/operators.go | 2 +- project-words.txt | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) 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