Skip to content

Keep StringUtils left, right, mid, and overlay off surrogate pair boundaries - #1776

Merged
garydgregory merged 1 commit into
apache:masterfrom
Alwaysgaurav1:fix/keep-left-right-mid-off-surrogates
Aug 22, 2026
Merged

Keep StringUtils left, right, mid, and overlay off surrogate pair boundaries#1776
garydgregory merged 1 commit into
apache:masterfrom
Alwaysgaurav1:fix/keep-left-right-mid-off-surrogates

Conversation

@Alwaysgaurav1

Copy link
Copy Markdown
Contributor

Summary

Prevents StringUtils.left, StringUtils.right, StringUtils.mid, and StringUtils.overlay from splitting UTF-16 surrogate pairs into malformed lone surrogates.

Details of Changes

  • StringUtils.left: Backs off the cut by 1 when splitsSurrogatePair is true to avoid trailing lone high surrogates.
  • StringUtils.right: Advances start by 1 when splitsSurrogatePair is true to avoid leading lone low surrogates.
  • StringUtils.mid: Adjusts start and end boundaries to keep cuts off the middle of surrogate pairs.
  • StringUtils.overlay: Adjusts replacement span boundaries off surrogate pairs.
  • Added comprehensive unit tests in StringUtilsSubstringTest and StringUtilsTest.
  • Added release notes entry in src/changes/changes.xml.

@skrcode

skrcode commented Aug 22, 2026

Copy link
Copy Markdown

JAIPilot Cloud reviewed exact head 164ab3a and found one small behavior-preserving cleanup: StringUtils.mid() computes the same surrogate-safe start position in both branches.

I opened a draft against the contributor branch: Alwaysgaurav1#1

The same 194 focused tests passed before/after, and the full Maven build passed with Checkstyle, SpotBugs, PMD, japicmp, and Javadoc. AI-assisted and independently scope-reviewed; no performance claim.

@garydgregory

Copy link
Copy Markdown
Member

Hello @Alwaysgaurav1
Please rebase on git master and resolve conflicts.
Thank you!

@Alwaysgaurav1
Alwaysgaurav1 force-pushed the fix/keep-left-right-mid-off-surrogates branch from 164ab3a to 0e049ac Compare August 22, 2026 16:07
@Alwaysgaurav1

Copy link
Copy Markdown
Contributor Author

Hi @garydgregory,

I have rebased the branch on master and resolved the merge conflicts. Thank you!

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT.

@garydgregory
garydgregory merged commit 73dadf0 into apache:master Aug 22, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants