diff --git a/pkg/yqlib/operator_add.go b/pkg/yqlib/operator_add.go index f0281bdf..5b95c34b 100644 --- a/pkg/yqlib/operator_add.go +++ b/pkg/yqlib/operator_add.go @@ -107,7 +107,11 @@ func addScalars(context Context, target *CandidateNode, lhs *yaml.Node, rhs *yam } else if lhsTag == "!!str" { target.Node.Tag = lhs.Tag - target.Node.Value = lhs.Value + rhs.Value + if rhsTag == "!!null" { + target.Node.Value = lhs.Value + } else { + target.Node.Value = lhs.Value + rhs.Value + } } else if rhsTag == "!!str" { target.Node.Tag = rhs.Tag target.Node.Value = lhs.Value + rhs.Value diff --git a/pkg/yqlib/operator_add_test.go b/pkg/yqlib/operator_add_test.go index eeabffde..918d0d39 100644 --- a/pkg/yqlib/operator_add_test.go +++ b/pkg/yqlib/operator_add_test.go @@ -225,6 +225,20 @@ var addOperatorScenarios = []expressionScenario{ "D0, P[], (!cool)::3cat\n", }, }, + { + skipDoc: true, + expression: `null + "cat"`, + expected: []string{ + "D0, P[], (!!str)::cat\n", + }, + }, + { + skipDoc: true, + expression: `"cat" + null`, + expected: []string{ + "D0, P[], (!!str)::cat\n", + }, + }, { description: "Number addition - float", subdescription: "If the lhs or rhs are floats then the expression will be calculated with floats.",