From 7e85d1cf54b1e467607a0019b56f91577ebe2e4f Mon Sep 17 00:00:00 2001 From: pascalschumacher Date: Sat, 21 May 2016 18:13:03 +0200 Subject: [PATCH] LANG-1226: StringUtils#normalizeSpace does not trim the string anymore (closes #150) --- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/lang3/StringUtils.java | 2 +- src/test/java/org/apache/commons/lang3/StringUtilsTest.java | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 41b14ff14..224e0343b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -46,6 +46,7 @@ The type attribute can be add,update,fix,remove. + StringUtils#normalizeSpace does not trim the string anymore SerializationUtils.ClassLoaderAwareObjectInputStream should use static initializer to initialize primitiveTypes map [GitHub issue #170] Add RandomUtils#nextBoolean() method FastDatePrinter generates extra Date objects diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 9bc639657..0ef2ff1d2 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -8220,7 +8220,7 @@ public class StringUtils { if (startWhitespaces) { return EMPTY; } - return new String(newChars, 0, count - (whitespacesCount > 0 ? 1 : 0)); + return new String(newChars, 0, count - (whitespacesCount > 0 ? 1 : 0)).trim(); } /** diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index a5c7bbb93..bd1b07d79 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -2614,6 +2614,8 @@ public class StringUtilsTest { assertEquals("a b c", StringUtils.normalizeSpace(" a b c ")); assertEquals("a b c", StringUtils.normalizeSpace("a\t\f\r b\u000B c\n")); assertEquals("a b c", StringUtils.normalizeSpace("a\t\f\r " + HARD_SPACE + HARD_SPACE + "b\u000B c\n")); + assertEquals("b", StringUtils.normalizeSpace("\u0000b")); + assertEquals("b", StringUtils.normalizeSpace("b\u0000")); } @Test