You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"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.
The text was updated successfully, but these errors were encountered:
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
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
butsubstr
seems broken.The text was updated successfully, but these errors were encountered: