Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Repo Assist] [JS/TS] Fix String.IndexOf/LastIndexOf ignoring StringComparison argument#4451

Draft
github-actions[bot] wants to merge 1 commit into
main from
repo-assist/fix-indexof-stringcomparison-61acf503a367968b
Draft

[Repo Assist] [JS/TS] Fix String.IndexOf/LastIndexOf ignoring StringComparison argument #4451
github-actions[bot] wants to merge 1 commit into
main from
repo-assist/fix-indexof-stringcomparison-61acf503a367968b

Conversation

@github-actions

@github-actions github-actions Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes #2601String.IndexOf and String.LastIndexOf with a StringComparison argument silently ignored the comparison, always performing ordinal case-sensitive search.

Root Cause

In Replacements.fs, the StringComparison enum value was explicitly filtered out of the argument list before calling native JS indexOf/lastIndexOf:

// Before: comparison filtered away, native indexOf used (always ordinal case-sensitive)
let args = args |> List.filter (function StringComparisonEnumValue -> false | _ -> true)
Helper.InstanceCall(c, "indexOf", t, args, ...)

This meant "Hello".IndexOf("h", StringComparison.OrdinalIgnoreCase) returned -1 instead of 0.

Fix

Two new functions added to String.ts:

  • indexOfWith(str, pattern, comparison, startIndex?) — forward search
  • lastIndexOfWith(str, pattern, comparison, startIndex?) — backward search

These handle all six StringComparison values:

  • Ordinal / InvariantCulture → native indexOf/lastIndexOf (fast path)
  • OrdinalIgnoreCase / InvariantCultureIgnoreCasetoLowerCase() loop
  • CurrentCulture / CurrentCultureIgnoreCaselocaleCompare loop with appropriate sensitivity

Replacements.fs now routes the two StringComparison patterns to these library functions, passing the comparison value as an argument rather than discarding it.

Test Plan

  • Added String.IndexOf OrdinalIgnoreCase works test
  • Added String.LastIndexOf OrdinalIgnoreCase works test
  • Existing StringComparison.Ordinal tests continue to pass

Closes #2601

🤖 Generated with Repo Assist

Note

🔒 Integrity filtering filtered 91 items

Integrity filtering activated and filtered the following items during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.

Generated by Repo Assist ·

To install this agentic workflow, run

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

Route IndexOf/LastIndexOf with StringComparison to new library functions
indexOfWith/lastIndexOfWith in String.ts, which correctly handle all
StringComparison values (Ordinal, OrdinalIgnoreCase, CurrentCulture,
CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase).
Previously the StringComparison argument was filtered out and the
native JS indexOf/lastIndexOf was used unconditionally (ordinal
case-sensitive), making case-insensitive searches silently return
wrong results.
Fixes #2601
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

automation Automated changes repo-assist Created by Repo Assist

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

String operations with StringComparison argument

0 participants

AltStyle によって変換されたページ (->オリジナル) /