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

prefer-string-slice makes a breaking change for negative lengths #700

Closed
sherlock1982 opened this issue Apr 27, 2020 · 2 comments · Fixed by #709
Closed

prefer-string-slice makes a breaking change for negative lengths #700

sherlock1982 opened this issue Apr 27, 2020 · 2 comments · Fixed by #709
Assignees
Labels

Comments

@sherlock1982
Copy link

sherlock1982 commented Apr 27, 2020

Consider the following autofix:

"Sample".substr(0, "Sample".lastIndexOf('/')) returns empty string.
Due to ECMA-262 "If length is a negative number, it is treated as 0."

Unicorn changes it to:
"Sample".slice(0, "Sample".lastIndexOf('/')) returns "Sampl".

I'm not sure if autofix shouldn't be breaking.
But i think you need to be aware of this behavior.

UPD: I see that in other places it correctly added Math.Max for substring but substr seems broken.

@sherlock1982 sherlock1982 changed the title prefer-string-slice is a breaking change for negative lengths prefer-string-slice makes a breaking change for negative lengths Apr 27, 2020
@fisker fisker added the bug label Apr 27, 2020
@fisker
Copy link
Collaborator

fisker commented Apr 27, 2020

/cc @voxpelli

@voxpelli
Copy link
Contributor

Right, related change: #424

Not sure if I have time to look at this right now, but maybe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants