commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [2/4] [lang] LANG-1118 Fix StringUtils.repeat(char, int) dealing with negative repeat value
Date Tue, 28 Apr 2015 19:37:23 GMT
LANG-1118 Fix StringUtils.repeat(char, int) dealing with negative repeat value


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/1b9d938d
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/1b9d938d
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/1b9d938d

Branch: refs/heads/master
Commit: 1b9d938d66a172b200fd90d4a61707852bdb4b8f
Parents: 8e7df02
Author: Loic Guibert <lfdummy-apache@yahoo.fr>
Authored: Thu Apr 23 15:41:51 2015 +0400
Committer: Benedikt Ritter <britter@apache.org>
Committed: Tue Apr 28 21:32:54 2015 +0200

----------------------------------------------------------------------
 src/main/java/org/apache/commons/lang3/StringUtils.java     | 3 +++
 src/test/java/org/apache/commons/lang3/StringUtilsTest.java | 7 +++++++
 2 files changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1b9d938d/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 360185c..2624572 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -5233,6 +5233,9 @@ public class StringUtils {
      * @see #repeat(String, int)
      */
     public static String repeat(final char ch, final int repeat) {
+        if (repeat <= 0) {
+            return EMPTY;
+        }
         final char[] buf = new char[repeat];
         for (int i = repeat - 1; i >= 0; i--) {
             buf[i] = ch;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1b9d938d/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index 5721dbc..8cac696 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -1375,6 +1375,13 @@ public class StringUtilsTest {
     }
 
     @Test
+    public void testRepeat_CharInt() {
+        assertEquals("zzz", StringUtils.repeat('z', 3));
+        assertEquals("", StringUtils.repeat('z', 0));
+        assertEquals("", StringUtils.repeat('z', -2));
+    }
+
+    @Test
     public void testChop() {
 
         final String[][] chopCases = {


Mime
View raw message