question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

string.StartsWith/EndsWith do not respect StringComparison arg.

See original GitHub issue

This 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:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Apr 12, 2021

Don’t worry I know all places which I have to fix. This is one of them.

0reactions
jack128commented, Apr 13, 2021

Well, FB doesnt have any special support for non-case sensitive search. So i’d use lower function. "lower(Field) starting with @p"

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found