@@ -63,7 +63,7 @@ export const evaluateRulesOnDict = (dict, rules, customizations) => {
63
63
}
64
64
for ( const [ index , rule ] of rules . entries ( ) ) {
65
65
// Only check customizations that are specified
66
- return evaluateSingleRuleOnDict ( dict , rule , index , customizations )
66
+ return evaluateSingleRuleOnDict ( dict , rule , index , customizations ) ;
67
67
}
68
68
// If no rules are met, return not found (index=-1)
69
69
return - 1 ;
@@ -81,8 +81,7 @@ export const evaluateSingleRuleOnDict = (dict, rule, ruleIndex, customizations)
81
81
}
82
82
}
83
83
return - 1 ;
84
- }
85
-
84
+ } ;
86
85
87
86
/**
88
87
* Evaluates the specified rule set on a node object returned by the Neo4j driver.
@@ -127,6 +126,20 @@ export const evaluateRules = (entity, customization, defaultValue, rules, entity
127
126
return defaultValue ;
128
127
} ;
129
128
129
+ /**
130
+ * @param realValue the value found in the real data returned by the query
131
+ * @param ruleValue the value specified in the rule.
132
+ * @returns whether the condition is met.
133
+ */
134
+ const isLooselyEqual = ( realValue , ruleValue ) => {
135
+ // In order to avoid having '5' <> {low: 5, high: 0} OR '5' <> 5
136
+ const sensitiveTypes = [ 'string' , 'number' , 'object' ] ;
137
+ if ( sensitiveTypes . includes ( typeof realValue ) && sensitiveTypes . includes ( typeof ruleValue ) ) {
138
+ return realValue == ruleValue ;
139
+ }
140
+ return realValue === ruleValue ;
141
+ } ;
142
+
130
143
/**
131
144
* @param realValue the value found in the real data returned by the query
132
145
* @param condition the condition, one of [=,!=,<,<=,>,>=,contains].
@@ -139,10 +152,10 @@ const evaluateCondition = (realValue, condition, ruleValue) => {
139
152
return false ;
140
153
}
141
154
if ( condition == '=' ) {
142
- return realValue === ruleValue ;
155
+ return isLooselyEqual ( realValue , ruleValue ) ;
143
156
}
144
157
if ( condition == '!=' ) {
145
- return realValue !== ruleValue ;
158
+ return ! isLooselyEqual ( realValue , ruleValue ) ;
146
159
}
147
160
if ( ! isNaN ( Number ( ruleValue ) ) ) {
148
161
ruleValue = Number ( ruleValue ) ;
0 commit comments