Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.replace incorrectly handles negative value for count #9181

Closed
Quarz0 opened this issue Aug 15, 2019 · 0 comments
Closed

string.replace incorrectly handles negative value for count #9181

Quarz0 opened this issue Aug 15, 2019 · 0 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug

Comments

@Quarz0
Copy link
Contributor

Quarz0 commented Aug 15, 2019

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.

zegl added a commit to zegl/bazel that referenced this issue Aug 22, 2019
Also update the name of the argument to be "count" instead of "maxsplit",
to match the Starlark spec.

This fixes bazelbuild#9181
zegl added a commit to zegl/bazel that referenced this issue Aug 22, 2019
Also update the name of the argument to be "count" instead of "maxsplit",
to match the Starlark spec.

This fixes bazelbuild#9181
@c-parsons c-parsons added P2 We'll consider working on this in future. (Assignee optional) type: bug and removed untriaged labels Sep 3, 2019
bazel-io pushed a commit that referenced this issue May 1, 2020
This is another change to bring string.replace() in line with the spec. Safe to modify the flag since it has not been released yet.

Eliminated use of parameterization in test suite since it caused test cases that didn't need it to be cloned.

Also add RELNOTES in this CL for the flag.

Follow-up work to #9181.

RELNOTES: Added --incompatible_string_replace_count, to make string.replace() behave as in Python.
PiperOrigin-RevId: 309483323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants