This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 0ae4eaffa Clarify surrogate handling in StringUtils.abbreviateMiddle
(#1907)
0ae4eaffa is described below
commit 0ae4eaffaf630c432c051fa95e7150f0bdcc1d20
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Dec 3 14:47:01 2026 +0000
Clarify surrogate handling in StringUtils.abbreviateMiddle (#1907)
Clarify abbreviateMiddle length limits and test endpoint removal
Qualify the Javadoc length guarantee with "when possible".
Add regression assertions for omitting the first or both endpoint
surrogate pairs.
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/StringUtils.java | 2 +-
src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java | 3 +++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ee0093241..67a9b5b00 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -130,6 +130,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Sergi Parpal,
Gary Gregory">Javadoc: StopWatch: split() can be called more than once
(#1899).</action>
<action type="fix" dev="ggregory" due-to="Josh Curry,
Gary Gregory">Avoid reading the reflection accessibility property for
nonreflective builders; resolve unset defaults once per instance on first
access and retain them across subsequent use.</action>
<action type="fix" dev="ggregory"
due-to="wenwenwu999-maker, Gary Gregory">[javadoc] Document null locales in
StringUtils lowerCase and upperCase #1906.</action>
+ <action type="fix" dev="ggregory"
due-to="wenwenwu999-maker, Gary Gregory">[javadoc] Clarify surrogate handling
in StringUtils.abbreviateMiddle (#1907).</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add immutable
DataSize and DataUnit types in org.apache.commons.lang3.unit with explicit
decimal and binary units.</action>
<!-- UPDATE -->
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 4d96b240b..050630057 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -412,7 +412,7 @@ public static String abbreviate(final String str, String
abbrevMarker, final int
}
/**
- * Abbreviates a String to at most the specified length by replacing its
middle characters with the supplied replacement String.
+ * Abbreviates a String, when possible, to at most the specified length by
replacing its middle characters with the supplied replacement String.
*
* <p>
* Abbreviation occurs only when all of the following conditions hold:
diff --git
a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
index 9dc019b6a..99503e363 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
@@ -218,6 +218,9 @@ void testAbbreviateMiddleSurrogatePair() {
assertEquals("a." + "b", StringUtils.abbreviateMiddle("a" + grin +
grin + "b", ".", 4));
// the tail cut skips the orphaned low surrogate so the middle is
never followed by one
assertEquals(grin + "..", StringUtils.abbreviateMiddle(grin + "abc" +
grin, "..", 5));
+ // The first or both endpoint characters can be omitted.
+ assertEquals(".c", StringUtils.abbreviateMiddle(grin + "abc", ".", 3));
+ assertEquals(".", StringUtils.abbreviateMiddle(grin + "abc" + grin,
".", 3));
// a cut that lands between two whole code points is unchanged
assertEquals("ab.d", StringUtils.abbreviateMiddle("ab" + grin + "cd",
".", 4));
assertEquals("ab.f", StringUtils.abbreviateMiddle("abcdef", ".", 4));