Skip to content

Update CaseInsensitiveSubstringSearch sample to .NET 10 - #2206

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/96283-substring-in-string-case-insensitive-csharp
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/96283-substring-in-string-case-insensitive-csharp

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets the CaseInsensitiveSubstringSearch sample from net7.0 to net10.0 across all three projects and moves the test and benchmark packages to their current stable versions (Microsoft.NET.Test.Sdk 18.10.0, MSTest 4.4.0, coverlet.collector 10.0.1, BenchmarkDotNet 0.15.8). The MSTest 2.x to 4.x jump needed no source changes.

One behaviour fix: RegexIsMatch passed the caller's search term straight in as a regular expression pattern. Terms such as "c.de", "z*" and "m|q" matched strings that do not contain them, and "(" threw a RegexParseException instead of returning false. It now wraps the term in Regex.Escape() and adds RegexOptions.CultureInvariant, which also fixes a miss under a Turkish culture.

Two explanatory comments record what Regex.Escape and CultureInvariant are for, and that LinqStringEquals matches whole separator-delimited words rather than substrings.

New test class SubstringSearchSemanticsTest, three test methods over eight cases, pins all of that. Build is clean at 0 warnings and 0 errors, and dotnet test --filter "FullyQualifiedName!~Live" reports 23 passed, 0 failed, 0 skipped on .NET 10.0.10.

Retarget all three projects from net7.0 to net10.0 and move the test and
benchmark packages to their current stable versions.

Make RegexIsMatch treat the search term as literal text with Regex.Escape
and add RegexOptions.CultureInvariant, so a term holding regex
metacharacters no longer matches the wrong strings or throws.

Add SubstringSearchSemanticsTest pinning three facts: LinqStringEquals
matches whole separator-delimited words rather than substrings, the
escaped regex search agrees with String.Contains on metacharacter terms,
and all four containment methods still match under a Turkish culture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant