Skip to content

[Repo Assist] Use explicit StringComparison.Ordinal for string comparisons (fixes #742)#1670

Merged
dsyme merged 3 commits intomainfrom
repo-assist/fix-issue-742-string-comparison-f3393c97c74b2c50
Feb 26, 2026
Merged

[Repo Assist] Use explicit StringComparison.Ordinal for string comparisons (fixes #742)#1670
dsyme merged 3 commits intomainfrom
repo-assist/fix-issue-742-string-comparison-f3393c97c74b2c50

Conversation

@github-actions
Copy link
Contributor

🤖 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.Ordinal to all StartsWith, EndsWith, and string IndexOf/Contains calls that were missing an explicit comparison type.

Root Cause

Calls to String.StartsWith, String.EndsWith, and String.Contains without a StringComparison argument default to the current culture on .NET Framework, which can behave unexpectedly in non-English locales. The project already used StringComparison.Ordinal / StringComparison.OrdinalIgnoreCase in 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.

File Changes
StructuralTypes.fs s.StartsWith("Record@")StringComparison.Ordinal
StructuralInference.fs str.EndsWith suffixStringComparison.Ordinal
NameUtils.fs name.Contains " "name.IndexOf(' ') >= 0
XmlRuntime.fs StartsWith "<" and EndsWith "/"/"\\"StringComparison.Ordinal
XmlInference.fs StartsWith "{" / StartsWith "["StringComparison.Ordinal
Http.fs StartsWith "bytes=", StartsWith "text/", StartsWith "application/", EndsWith "+xml", EndsWith "+json"StringComparison.Ordinal; url.Contains "?"url.IndexOf('?') >= 0
XmlGenerator.fs StartsWith childName, EndsWith "List"/"Array"/"Collection", StartsWith "FSharpOption\1"StringComparison.Ordinal`
CsvRuntime.fs Contains "\t"IndexOf('\t') >= 0; Contains separator/quote/"\n"IndexOf(..., StringComparison.Ordinal) >= 0
JsonSchema.fs StartsWith("#/")StringComparison.Ordinal
HtmlOperations.fs EndsWith value / StartsWith value (CSS selector) → StringComparison.Ordinal
HtmlParser.fs ToLower()ToLowerInvariant()

netstandard2.0 Compatibility

string.Contains(string, StringComparison) is only available in .NET Standard 2.1+. For Contains calls, this PR uses:

  • IndexOf(char) for single-character literals (inherently ordinal, available everywhere)
  • IndexOf(string, StringComparison.Ordinal) >= 0 for 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.

Generated by Repo Assist for issue #742

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@afb00b92a9514fee9a14c583f059a03d05738f70

…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 dsyme marked this pull request as ready for review February 26, 2026 15:17
@dsyme dsyme merged commit c847d49 into main Feb 26, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-742-string-comparison-f3393c97c74b2c50 branch February 26, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cultural processing of strings: tidy up

1 participant