Equals now only compares scalars

This commit is contained in:
Mike Farah 2021-02-05 09:49:40 +11:00
parent 3c466dc66e
commit f92a42e4f8
2 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,7 @@
package yqlib
import "gopkg.in/yaml.v3"
func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- equalsOperation")
return crossFunction(d, context, expressionNode, isEquals)
@ -13,7 +15,7 @@ func isEquals(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Ca
if lhsNode.Tag == "!!null" {
value = (rhsNode.Tag == "!!null")
} else {
} else if lhsNode.Kind == yaml.ScalarNode && rhsNode.Kind == yaml.ScalarNode {
value = matchKey(lhsNode.Value, rhsNode.Value)
}
log.Debugf("%v == %v ? %v", NodeToString(lhs), NodeToString(rhs), value)

View File

@ -14,6 +14,14 @@ var equalsOperatorScenarios = []expressionScenario{
"D0, P[], (!!bool)::false\n",
},
},
{
skipDoc: true,
document: "{a: { b: {things: \"\"}, f: [1], g: [] }}",
expression: ".. | select(. == \"\")",
expected: []string{
"D0, P[a b things], (!!str)::\"\"\n",
},
},
{
description: "Match string",
document: `[cat,goat,dog]`,