[Repo Assist] [JS/TS + Python] Fix String.Contains ignoring StringComparison argument#4485
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
…ython targets
When calling String.Contains with a StringComparison argument (e.g.
StringComparison.OrdinalIgnoreCase), Fable was silently discarding the
second argument and always doing a case-sensitive search. This caused
incorrect results: e.g. "ABC".Contains("b", StringComparison.OrdinalIgnoreCase)
returned false instead of true.
Fix:
- Add contains(str, pattern, ic) to fable-library-ts/String.ts using
the existing cmp() helper (same pattern as startsWith/endsWith)
- Add contains(string, value, comparison) to fable_library/string_.py
(pure Python, handles ignore-case variants)
- Update Replacements.fs (JS/TS) and Python/Replacements.fs to route
Contains(value, comparison) to the new library function instead of
warning and ignoring the comparison argument
- Add regression tests to tests/Js/Main/StringTests.fs and
tests/Python/TestString.fs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
18 tasks
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 PR was created by Repo Assist, an automated AI assistant.
Summary
String.Contains(value, StringComparison)was silently discarding theStringComparisonargument and always performing a case-sensitive search. This produced incorrect results, e.g.:Root Cause
In both
Replacements.fs(JS/TS) andPython/Replacements.fs, theContainspattern matchedarg :: _and emitted a compile-time warning plus a case-sensitiveindexOf/findcall regardless of the second argument.Fix
JS/TS:
contains(str, pattern, ic)tosrc/fable-library-ts/String.ts, using the existingcmp()helper (same pattern asstartsWith/endsWith)Replacements.fsto routeContains(value, comparison)toString.containsfrom the libraryPython:
contains(string, value, comparison)tosrc/fable-library-py/fable_library/string_.py— pure Python implementation that handles all ignore-caseStringComparisonvariantsPython/Replacements.fssimilarlyTests:
String.Contains with StringComparison workstotests/Js/Main/StringTests.fstest String.Contains with StringComparison workstotests/Python/TestString.fsTrade-offs
The JS
containsfunction uses a character-by-character scan for culture-sensitive comparisons (same strategy asstartsWith/endsWith). For the commonOrdinalIgnoreCasecase the loop'scmp()call uses simpletoLowerCase(), which is fast in practice.Note
🔒 Integrity filter blocked 84 items
The following items were blocked because they don't meet the GitHub integrity level.
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".EntryPoint#2366list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter: