string.StartsWith/EndsWith do not respect StringComparison arg.
See original GitHub issueThis bug hits atleast Firebird and Sqlite providers.
[Test, Combinatorial]
public void SearchStringTest(
[IncludeDataSources(TestProvName.AllSQLite, TestProvName.AllFirebird)] string context,
[Values(nameof(string.StartsWith), nameof(string.EndsWith))] string methodName,
[Values]bool ignoreCase)
{
var stringComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
Expression<Func<Model.Person, bool>> GetPredicate(string param) => methodName switch
{
nameof(string.StartsWith) => (Model.Person p) => p.LastName.StartsWith(param, stringComparison),
nameof(string.EndsWith) => (Model.Person p) => p.LastName.EndsWith(param, stringComparison),
_ => throw new ArgumentException("Unknown method name " + methodName)
};
using (var db = GetDataContext(context))
{
Assert.IsTrue(db.Person.Any(GetPredicate("Pupkin")));
Assert.AreEqual(ignoreCase, db.Person.Any(GetPredicate("pupkin")));
}
}
Also there is FB specific issue in FirebirdSqlOptimizer.ConvertSearchStringPredicate. “starting with” is case-sensitive, but linq2db use it in “ignorecase” branch
Environment details
linq2db version: 3.3 Database Server: Firebird
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
String.StartsWith Method (System)
Determines whether this string instance starts with the specified character. StartsWith(String) ... comparisonType is not a StringComparison value.
Read more >How to use `string.startsWith()` method ignoring the case?
Another option is to use String#regionMatches() method, which takes a boolean argument stating whether to do case-sensitive matching or not.
Read more >String.EndsWith Method (System)
EndsWith (String, StringComparison) Determines whether the end of this string instance matches the specified string when compared using the specified comparison ...
Read more >"StartsWith" and "EndsWith" overloads that take a "char ...
With string.StartsWith(char) and string.EndsWith(char) , only the first character of the string is compared to the provided character, whereas the string ...
Read more >Java String startsWith() And endsWith() Methods
Java String startsWith() And endsWith() Methods: The startsWith accepts a string and checks whether the invoking string starts with the given string or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Don’t worry I know all places which I have to fix. This is one of them.
Well, FB doesnt have any special support for non-case sensitive search. So i’d use lower function.
"lower(Field) starting with @p"