From e9fe426f7f3137b346217714f001c9797bac4af1 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Tue, 15 Nov 2011 23:26:43 -0500 Subject: [PATCH] fix unicodeTrim on all-whitespace strings --- src/main/java/com/typesafe/config/impl/ConfigUtil.java | 4 ++-- src/test/scala/com/typesafe/config/impl/UtilTest.scala | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/typesafe/config/impl/ConfigUtil.java b/src/main/java/com/typesafe/config/impl/ConfigUtil.java index 65ae09af..fff540e1 100644 --- a/src/main/java/com/typesafe/config/impl/ConfigUtil.java +++ b/src/main/java/com/typesafe/config/impl/ConfigUtil.java @@ -79,7 +79,7 @@ final public class ConfigUtil { return s; int start = 0; - while (true) { + while (start < length) { char c = s.charAt(start); if (c == ' ' || c == '\n') { start += 1; @@ -93,7 +93,7 @@ final public class ConfigUtil { } int end = length; - while (true) { + while (end > start) { char c = s.charAt(end - 1); if (c == ' ' || c == '\n') { --end; diff --git a/src/test/scala/com/typesafe/config/impl/UtilTest.scala b/src/test/scala/com/typesafe/config/impl/UtilTest.scala index 2aec06d9..6f04a16f 100644 --- a/src/test/scala/com/typesafe/config/impl/UtilTest.scala +++ b/src/test/scala/com/typesafe/config/impl/UtilTest.scala @@ -21,6 +21,7 @@ class UtilTest extends TestUtils { assertEquals("", ConfigUtil.unicodeTrim("")) assertEquals("a", ConfigUtil.unicodeTrim("a")) assertEquals("abc", ConfigUtil.unicodeTrim("abc")) + assertEquals("", ConfigUtil.unicodeTrim(" \n \n \u00A0 ")) assertEquals(supplementaryChars, ConfigUtil.unicodeTrim(supplementaryChars)) val s = " \u00A0 \n " + supplementaryChars + " \n \u00A0 "