diff --git a/pkg/yqlib/candidate_node.go b/pkg/yqlib/candidate_node.go index da037a75..87941c31 100644 --- a/pkg/yqlib/candidate_node.go +++ b/pkg/yqlib/candidate_node.go @@ -86,7 +86,14 @@ func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode) { if n.Node.Style == 0 { n.Node.Style = other.Node.Style } - n.Node.FootComment = n.Node.FootComment + other.Node.FootComment - n.Node.HeadComment = n.Node.HeadComment + other.Node.HeadComment - n.Node.LineComment = n.Node.LineComment + other.Node.LineComment + + if other.Node.FootComment != "" { + n.Node.FootComment = other.Node.FootComment + } + if other.Node.HeadComment != "" { + n.Node.HeadComment = other.Node.HeadComment + } + if other.Node.LineComment != "" { + n.Node.LineComment = other.Node.LineComment + } } diff --git a/pkg/yqlib/operator_multiply.go b/pkg/yqlib/operator_multiply.go index 573160c1..eb892698 100644 --- a/pkg/yqlib/operator_multiply.go +++ b/pkg/yqlib/operator_multiply.go @@ -31,6 +31,7 @@ func multiply(preferences multiplyPreferences) func(d *dataTreeNavigator, contex (lhs.Node.Kind == yaml.SequenceNode && rhs.Node.Kind == yaml.SequenceNode) { var newBlank = lhs.CreateChild(nil, &yaml.Node{}) + var newThing, err = mergeObjects(d, context, newBlank, lhs, multiplyPreferences{}) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_multiply_test.go b/pkg/yqlib/operator_multiply_test.go index a903966c..52e14a85 100644 --- a/pkg/yqlib/operator_multiply_test.go +++ b/pkg/yqlib/operator_multiply_test.go @@ -4,6 +4,26 @@ import ( "testing" ) +var doc1 = `list: +# Hi this is a comment. +# Hello this is another comment. +- "abc"` + +var doc2 = `list2: +# This is yet another comment. +# Indeed this is yet another comment. +- "123"` + +var docExpected = `D0, P[], (!!map)::list: + # Hi this is a comment. + # Hello this is another comment. + - "abc" +list2: + # This is yet another comment. + # Indeed this is yet another comment. + - "123" +` + var multiplyOperatorScenarios = []expressionScenario{ { description: "Multiply integers", @@ -12,6 +32,15 @@ var multiplyOperatorScenarios = []expressionScenario{ "D0, P[], (!!int)::12\n", }, }, + { + skipDoc: true, + document: doc1, + document2: doc2, + expression: `select(fi == 0) * select(fi == 1)`, + expected: []string{ + docExpected, + }, + }, { skipDoc: true, expression: `3 * 4.5`,