Skip to content

Fix WordUtils.wrap for wrapOn matches different from one character#1655

Merged
garydgregory merged 1 commit into
masterfrom
fix/pattern-length
May 17, 2026
Merged

Fix WordUtils.wrap for wrapOn matches different from one character#1655
garydgregory merged 1 commit into
masterfrom
fix/pattern-length

Conversation

@ppkarwasz
Copy link
Copy Markdown
Member

@ppkarwasz ppkarwasz commented May 17, 2026

WordUtils.wrap advanced the offset by a single character past each wrapOn match, assuming the separator is always exactly one character long:

  • When the wrapOn regex matched several characters, the surplus separator characters were left in the wrapped output instead of being consumed,
  • When the wrapOn regex matched zero characters, one additional character was consumed.

Now it tracks the end offset of each match and resume from there, so that separators of any length, including zero-width matches, are skipped correctly.

  • I used AI to refactor tests and reword descriptions

`WordUtils.wrap` advanced the offset by a single character past each `wrapOn` match, assuming the separator is always exactly one character long:

 - When the `wrapOn` regex matched several characters, the surplus separator characters were left in the wrapped output instead of being consumed,
 - When the `wrapOn` regex matched zero characters, one additional character was consumed.

Now it tracks the end offset of each match and resume from there, so that separators of any length, including zero-width matches, are skipped correctly.
@garydgregory
Copy link
Copy Markdown
Member

@ppkarwasz
Please stop creating branches in this repo, use your fork. It's too easy to have orphan branches.

@garydgregory garydgregory merged commit 9f7d3b5 into master May 17, 2026
45 of 52 checks passed
@garydgregory garydgregory deleted the fix/pattern-length branch May 17, 2026 22:54
@ppkarwasz
Copy link
Copy Markdown
Member Author

@garydgregory, no problem. I saw your message on the mailing list (thread) and will submit PRs from my fork going forward.

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.

2 participants