Skip to content

Commit 6059a38

Browse files
committed
fix: changed equality to case insensitive
1 parent 3853460 commit 6059a38

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/GoatQuery/src/Evaluator/FilterEvaluator.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ private static Result<Expression> CreateComparisonExpression(string operatorKeyw
202202
{
203203
return operatorKeyword switch
204204
{
205-
Keywords.Eq => Expression.Equal(expression, value),
206-
Keywords.Ne => Expression.NotEqual(expression, value),
205+
Keywords.Eq => CreateEqualityExpression(expression, value, isEqual: true),
206+
Keywords.Ne => CreateEqualityExpression(expression, value, isEqual: false),
207207
Keywords.Contains => CreateContainsExpression(expression, value),
208208
Keywords.Lt => Expression.LessThan(expression, value),
209209
Keywords.Lte => Expression.LessThanOrEqual(expression, value),
@@ -263,6 +263,24 @@ private static Expression CreateContainsExpression(Expression expression, Consta
263263
return Expression.Call(expressionToLower, StringContainsMethod, valueToLower);
264264
}
265265

266+
private static Expression CreateEqualityExpression(Expression expression, ConstantExpression value, bool isEqual)
267+
{
268+
// For string comparisons, make them case-insensitive
269+
if (expression.Type == typeof(string))
270+
{
271+
var expressionToLower = Expression.Call(expression, StringToLowerMethod);
272+
var valueToLower = Expression.Call(value, StringToLowerMethod);
273+
return isEqual
274+
? Expression.Equal(expressionToLower, valueToLower)
275+
: Expression.NotEqual(expressionToLower, valueToLower);
276+
}
277+
278+
// For non-string types, use standard equality
279+
return isEqual
280+
? Expression.Equal(expression, value)
281+
: Expression.NotEqual(expression, value);
282+
}
283+
266284
private static Result<Expression> EvaluateInfixExpression(InfixExpression exp, FilterEvaluationContext context)
267285
{
268286
if (exp.Left is PropertyPath propertyPath)

src/GoatQuery/tests/Filter/FilterTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ public static IEnumerable<object[]> Parameters()
440440
"gender ne null and status eq 1",
441441
new[] { TestData.Users["User03"] }
442442
};
443+
444+
yield return new object[] {
445+
"firstname eq 'user01'",
446+
new[] { TestData.Users["User01"] }
447+
};
443448
}
444449

445450
[Theory]

0 commit comments

Comments
 (0)