diff --git a/pkg/yqlib/operator_add.go b/pkg/yqlib/operator_add.go index a524b9ba..3de2299e 100644 --- a/pkg/yqlib/operator_add.go +++ b/pkg/yqlib/operator_add.go @@ -103,6 +103,9 @@ 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 + } else if rhsTag == "!!str" { + target.Node.Tag = rhs.Tag + target.Node.Value = lhs.Value + rhs.Value } else if lhsTag == "!!int" && rhsTag == "!!int" { format, lhsNum, err := parseInt64(lhs.Value) if err != nil { diff --git a/pkg/yqlib/operator_add_test.go b/pkg/yqlib/operator_add_test.go index a98e3faf..2b9c6008 100644 --- a/pkg/yqlib/operator_add_test.go +++ b/pkg/yqlib/operator_add_test.go @@ -199,6 +199,24 @@ var addOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::{a: catmeow, b: meow}\n", }, }, + { + description: "String concatenation - str + int", + skipDoc: true, + document: `{a: !cool cat, b: meow}`, + expression: `.a + 3`, + expected: []string{ + "D0, P[a], (!cool)::cat3\n", + }, + }, + { + description: "String concatenation - int + str", + skipDoc: true, + document: `{a: !cool cat, b: meow}`, + expression: `3 + .a`, + expected: []string{ + "D0, P[], (!cool)::3cat\n", + }, + }, { description: "Number addition - float", subdescription: "If the lhs or rhs are floats then the expression will be calculated with floats.",