kzhunmax opened a new pull request, #763:
URL: https://github.com/apache/commons-text/pull/763
`StrBuilder.lastIndexOf(String)` and `extStringBuilder.lastIndexOf(String)`
do not match `java.lang.String` / `StringBuilder` for the empty string.
For a builder of length n, `lastIndexOf("")` should return n (empty match
at the end). Both implementations currently return `n - 1`.
Cause:
`lastIndexOf(String, int) `clamps startIndex with:
`startIndex = startIndex >= size ? size - 1 : startIndex`
before the empty-string case, which returns that clamped index. So
`lastIndexOf("")` can never return size.
Example:
```
new StrBuilder("abab").lastIndexOf("") // actual 3, expected 4
"abab".lastIndexOf("") // 4
new StringBuilder("abab").lastIndexOf("") // 4
Same issue in TextStringBuilder.
```
Fix:
In `lastIndexOf(String, int)`, for an empty search string allow the start
index up to size and return that, keep the existing `size - 1` clamp for
non-empty strings.
Affects:
- org.apache.commons.text.StrBuilder
- org.apache.commons.text.TextStringBuilder
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]