alhudz opened a new pull request, #1770:
URL: https://github.com/apache/commons-lang/pull/1770

   `StringUtils.chop` cuts the last UTF-16 char, so a `String` ending in a 
supplementary code point is left holding a lone surrogate.
   
   Repro: `chop("x😀")`, a `String` ending in `U+1F600`.
   Expected: `"x"`, dropping the whole trailing code point, the same way 
`chop("a")` returns `""`.
   Actual: `"x\uD83D"`, only the low surrogate is removed and a lone high 
surrogate is left behind (malformed UTF-16).
   Cause: the cut is `str.substring(0, length - 1)` with no surrogate check, 
unlike the sibling `abbreviate`/`truncate` which already guard their cuts with 
`splitsSurrogatePair`.
   Fix: reuse `splitsSurrogatePair(str, length - 1)` to drop both halves when 
the final char is a low surrogate. The `\r\n` handling and every documented 
example stay unchanged.
   
   - [x] Read the contribution guidelines for this project.
   - [ ] Read the ASF Generative Tooling Guidance if you use Artificial 
Intelligence (AI).
   - [ ] I used AI to create any part of, or all of, this pull request.
   - [x] Run a successful build using the default Maven goal with `mvn`.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request has a meaningful subject line and body.
   


-- 
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]

Reply via email to