Skip to content

Commit 165b06d

Browse files
committed
Fix C# impl of ILike to be case insensitive
Fixes #267
1 parent 954f0d6 commit 165b06d

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/EFCore.PG/NpgsqlDbFunctionsExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static bool ILike(
2020
[CanBeNull] this DbFunctions _,
2121
[CanBeNull] string matchExpression,
2222
[CanBeNull] string pattern)
23-
=> LikeCore(matchExpression, pattern, escapeCharacter: null);
23+
=> ILikeCore(matchExpression, pattern, escapeCharacter: null);
2424

2525
/// <summary>
2626
/// An implementation of the PostgreSQL ILIKE operation, which is an insensitive LIKE.
@@ -38,7 +38,7 @@ public static bool ILike(
3838
[CanBeNull] string matchExpression,
3939
[CanBeNull] string pattern,
4040
[CanBeNull] string escapeCharacter)
41-
=> LikeCore(matchExpression, pattern, escapeCharacter);
41+
=> ILikeCore(matchExpression, pattern, escapeCharacter);
4242

4343
// Regex special chars defined here:
4444
// https://msdn.microsoft.com/en-us/library/4edbef7e(v=vs.110).aspx
@@ -56,7 +56,7 @@ private static string BuildEscapeRegexCharsPattern(IEnumerable<char> regexSpecia
5656
return string.Join("|", regexSpecialChars.Select(c => @"\" + c));
5757
}
5858

59-
private static bool LikeCore(string matchExpression, string pattern, string escapeCharacter)
59+
private static bool ILikeCore(string matchExpression, string pattern, string escapeCharacter)
6060
{
6161
//TODO: this fixes https://github.com/aspnet/EntityFramework/issues/8656 by insisting that
6262
// the "escape character" is a string but just using the first character of that string,
@@ -133,7 +133,7 @@ var regexPattern
133133
return Regex.IsMatch(
134134
matchExpression,
135135
@"\A" + regexPattern + @"\s*\z",
136-
RegexOptions.Singleline,
136+
RegexOptions.IgnoreCase | RegexOptions.Singleline,
137137
_regexTimeout);
138138
}
139139
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
8+
// ReSharper disable InconsistentNaming
9+
10+
namespace Microsoft.EntityFrameworkCore
11+
{
12+
public class NpgsqlDbFunctionsTest
13+
{
14+
readonly DbFunctions _functions = EF.Functions;
15+
16+
[Fact]
17+
public void ILike_when_no_wildcards()
18+
{
19+
Assert.True(_functions.ILike("abc", "abc"));
20+
Assert.True(_functions.ILike("abc", "ABC"));
21+
Assert.True(_functions.ILike("ABC", "abc"));
22+
23+
Assert.False(_functions.ILike("ABC", "ab"));
24+
Assert.False(_functions.ILike("ab", "abc"));
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)