Conversation
…t codebase Fixes all cases of String.StartsWith, String.EndsWith, String.Contains and String.IndexOf (with string argument) that were missing an explicit StringComparison argument, as identified in issue #742. Changes: - Use StringComparison.Ordinal for all StartsWith/EndsWith comparisons on ASCII/code identifiers and syntax strings - Replace String.Contains with IndexOf(char) for single-char literals (netstandard2.0 compatible) or IndexOf(string, StringComparison.Ordinal) for variable string arguments - Replace ToLower() with ToLowerInvariant() in HtmlParser Files changed: - src/FSharp.Data.Runtime.Utilities/StructuralTypes.fs - src/FSharp.Data.Runtime.Utilities/StructuralInference.fs - src/FSharp.Data.Runtime.Utilities/NameUtils.fs - src/FSharp.Data.Xml.Core/XmlRuntime.fs - src/FSharp.Data.Xml.Core/XmlInference.fs - src/FSharp.Data.Http/Http.fs - src/FSharp.Data.DesignTime/Xml/XmlGenerator.fs - src/FSharp.Data.Csv.Core/CsvRuntime.fs - src/FSharp.Data.Json.Core/JsonSchema.fs - src/FSharp.Data.Html.Core/HtmlOperations.fs - src/FSharp.Data.Html.Core/HtmlParser.fs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is a pull request from Repo Assist, an automated AI assistant.
Closes #742
Summary
This PR addresses the consistency issue raised in #742 by adding explicit
StringComparison.Ordinalto allStartsWith,EndsWith, and stringIndexOf/Containscalls that were missing an explicit comparison type.Root Cause
Calls to
String.StartsWith,String.EndsWith, andString.Containswithout aStringComparisonargument default to the current culture on .NET Framework, which can behave unexpectedly in non-English locales. The project already usedStringComparison.Ordinal/StringComparison.OrdinalIgnoreCasein many places — these changes make the remaining calls consistent.Changes
All comparisons involve ASCII code/syntax strings (e.g.
"?","#/","Record@","text/","FSharpOption\1"`) where ordinal comparison is clearly correct.StructuralTypes.fss.StartsWith("Record@")→StringComparison.OrdinalStructuralInference.fsstr.EndsWith suffix→StringComparison.OrdinalNameUtils.fsname.Contains " "→name.IndexOf(' ') >= 0XmlRuntime.fsStartsWith "<"andEndsWith "/"/"\\"→StringComparison.OrdinalXmlInference.fsStartsWith "{"/StartsWith "["→StringComparison.OrdinalHttp.fsStartsWith "bytes=",StartsWith "text/",StartsWith "application/",EndsWith "+xml",EndsWith "+json"→StringComparison.Ordinal;url.Contains "?"→url.IndexOf('?') >= 0XmlGenerator.fsStartsWith childName,EndsWith "List"/"Array"/"Collection",StartsWith "FSharpOption\1"→StringComparison.Ordinal`CsvRuntime.fsContains "\t"→IndexOf('\t') >= 0;Contains separator/quote/"\n"→IndexOf(..., StringComparison.Ordinal) >= 0JsonSchema.fsStartsWith("#/")→StringComparison.OrdinalHtmlOperations.fsEndsWith value/StartsWith value(CSS selector) →StringComparison.OrdinalHtmlParser.fsToLower()→ToLowerInvariant()netstandard2.0 Compatibility
string.Contains(string, StringComparison)is only available in .NET Standard 2.1+. ForContainscalls, this PR uses:IndexOf(char)for single-character literals (inherently ordinal, available everywhere)IndexOf(string, StringComparison.Ordinal) >= 0for variable string arguments (available since .NET Framework 2.0)Test Status
✅ Build passes with 0 errors (
dotnet build FSharp.Data.sln -c Release). These are all purely mechanical changes with no behavioral impact on correctly-configured systems.