Skip to content

string.replace incorrectly handles negative value for count #9181

@Quarz0

Description

@Quarz0

Description of the problem:

According to the spec, a negative value for count in string.replace should be ignored and this is also what python and the Go implementation do.

# Current implementation
"abc".replace("a", "z", -1)    # "abc"

# Python/Go
"abc".replace("a", "z", -1)    # "zbc"

Side Note: The parameter count of string.replace is incorrectly named maxsplit in the definition of replace here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2We'll consider working on this in future. (Assignee optional)type: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions