Skip to content

Commit ba4a671

Browse files
authored
Update StringUtils.java
The current trim function does not trim down the non-breaking spaces, zero-width spaces, or other invisible characters. Added logic for that too.
1 parent 26bb2d1 commit ba4a671

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/java/org/apache/commons/lang3/StringUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8761,7 +8761,8 @@ public static String toString(final byte[] bytes, final String charsetName) {
87618761
}
87628762

87638763
/**
8764-
* Removes control characters (char <= 32) from both
8764+
* Removes control characters (char <= 32) and any other hidden
8765+
* space character from both
87658766
* ends of this String, handling {@code null} by returning
87668767
* {@code null}.
87678768
*
@@ -8784,7 +8785,7 @@ public static String toString(final byte[] bytes, final String charsetName) {
87848785
* @return the trimmed string, {@code null} if null String input
87858786
*/
87868787
public static String trim(final String str) {
8787-
return str == null ? null : str.trim();
8788+
return str == null ? null : str.replaceAll("\\p{C}", "").trim();
87888789
}
87898790

87908791
/**

0 commit comments

Comments
 (0)