Skip to content

ROS<T>.LastIndexOf(ROS<T> value) returns wrong index when 'value' is empty #13382

Closed

Description

@GrabYourPitchforks
Console.WriteLine("Hello".LastIndexOf(""));
Console.WriteLine("Hello".LastIndexOf("", StringComparison.Ordinal));
Console.WriteLine("Hello".AsSpan().LastIndexOf(""));
Console.WriteLine("Hello".AsSpan().LastIndexOf("", StringComparison.Ordinal));

// PRINTS:
// 4
// 4
// 0
// 4

The behavior of ROS<T>.LastIndexOf differs based on whether the char-specific overload is called or whether the generic T overload is called, as shown above. We should make the behavior consistent.

(To be fair, all of these APIs should be returning "5", not "4". I'll file a separate bug for that.)

Activity

  1. hannan-sultan commented on Sep 21, 2019

    @hannan-sultan

    I'm willing to take this issue. I have cloned the repo and followed the building on Windows instructions everything builds fine. I guess the fix should be in CompareInfo.cs in System.Private.Corelib project, right?
    Can you please guide me on how I can test after making changes?

  2. GrabYourPitchforks commented on Sep 27, 2019

    @GrabYourPitchforks
    MemberAuthor

    Hi @hannan-sultan! Check https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md#testing-with-private-coreclr-bits for complete instructions. But in a nutshell, what this involves is essentially four steps:

    1. Clone the coreclr and corefx repos.
    2. Make the change in coreclr and build it locally.
    3. Build corefx locally using the custom coreclr you've built. (build -build -buildtests /p:coreclroverridepath=c:\whatever)
    4. Run the corefx tests locally (build -test /p:coreclroverridepath=c:\whatever)

    It's likely that you'll see corefx test failures, as the tests probably test the incorrect behavior. If this occurs make the changes to your local corefx repo, then rebuild and rerun the tests.

  3. transferred this issue fromdotnet/coreclron Jan 31, 2020
  4. added this to the 5.0 milestone on Jan 31, 2020
  5. added
    untriaged
    on Feb 26, 2020
  6. removed
    untriaged
    help wanted
    on Apr 7, 2020
  7. ghost locked as resolved and limited conversation to collaborators on Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions