mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-07 02:48:27 +08:00
Fixing add when there is no node match #2325
This commit is contained in:
@@ -39,13 +39,19 @@ func toNodes(candidate *CandidateNode, lhs *CandidateNode) []*CandidateNode {
|
||||
func addOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||||
log.Debugf("Add operator")
|
||||
|
||||
return crossFunction(d, context.ReadOnlyClone(), expressionNode, add, false)
|
||||
return crossFunction(d, context.ReadOnlyClone(), expressionNode, add, true)
|
||||
}
|
||||
|
||||
func add(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
||||
lhsNode := lhs
|
||||
|
||||
if lhsNode.Tag == "!!null" {
|
||||
if lhs == nil && rhs == nil {
|
||||
return nil, nil
|
||||
} else if lhs == nil {
|
||||
return rhs.Copy(), nil
|
||||
} else if rhs == nil {
|
||||
return lhs.Copy(), nil
|
||||
} else if lhsNode.Tag == "!!null" {
|
||||
return lhs.CopyAsReplacement(rhs), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user