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

   Follow-up to #1776.
   
   ### Problem
   When padding strings with supplementary characters (surrogate pairs) such as 
emoji, `StringUtils.leftPad()`, `StringUtils.rightPad()`, and 
`StringUtils.center()` previously sliced or repeated `padStr` strictly by 
`char` count. If the target padding length cut midway through a 2-char 
surrogate pair, the resulting string was left with an unpaired high surrogate 
(`\uD83D`), producing malformed Unicode.
   
   ### Solution
   - Check `splitsSurrogatePair(padStr, pads % padLen)` before repeating or 
substringing `padStr`.
   - When a cut falls on a surrogate pair boundary, decrement `pads` by 1 so 
the padding boundary never splits a surrogate pair.
   - Since `StringUtils.center()` delegates to `leftPad` and `rightPad`, 
centering with surrogate pairs is also protected against lone surrogates.
   - Added comprehensive unit tests and property/fuzz tests in 
`StringUtilsTest` covering various surrogate lengths and string combinations.
   - Updated `changes.xml` under release `3.21.1`.


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