Fix IndexOutOfBoundsException on padding

bug 35756, from Reuben Sivan

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@240418 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-08-27 13:40:14 +00:00
parent 60c6443387
commit 7ea69942ef
3 changed files with 6 additions and 1 deletions

View File

@ -301,6 +301,9 @@ limitations under the License.
<contributor> <contributor>
<name>Sean Schofield</name> <name>Sean Schofield</name>
</contributor> </contributor>
<contributor>
<name>Reuben Sivan</name>
</contributor>
<contributor> <contributor>
<name>Ville Skytta</name> <name>Ville Skytta</name>
</contributor> </contributor>

View File

@ -110,6 +110,7 @@ import java.util.List;
* @author Phil Steitz * @author Phil Steitz
* @author Al Chou * @author Al Chou
* @author Michael Davey * @author Michael Davey
* @author Reuben Sivan
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id$
*/ */
@ -152,7 +153,7 @@ public class StringUtils {
* *
* <p>Used for efficient space padding. The length of each String expands as needed.</p> * <p>Used for efficient space padding. The length of each String expands as needed.</p>
*/ */
private static final String[] PADDING = new String[Character.MAX_VALUE]; private static final String[] PADDING = new String[Character.MAX_VALUE + 1];
static { static {
// space padding is most common, start with 64 chars // space padding is most common, start with 64 chars

View File

@ -1126,6 +1126,7 @@ public class StringUtilsTest extends TestCase {
assertEquals(" ", StringUtils.leftPad("", 5, ' ')); assertEquals(" ", StringUtils.leftPad("", 5, ' '));
assertEquals(" abc", StringUtils.leftPad("abc", 5, ' ')); assertEquals(" abc", StringUtils.leftPad("abc", 5, ' '));
assertEquals("xxabc", StringUtils.leftPad("abc", 5, 'x')); assertEquals("xxabc", StringUtils.leftPad("abc", 5, 'x'));
assertEquals("\uffff\uffffabc", StringUtils.leftPad("abc", 5, '\uffff'));
assertEquals("abc", StringUtils.leftPad("abc", 2, ' ')); assertEquals("abc", StringUtils.leftPad("abc", 2, ' '));
String str = StringUtils.leftPad("aaa", 10000, 'a'); // bigger than pad length String str = StringUtils.leftPad("aaa", 10000, 'a'); // bigger than pad length
assertEquals(10000, str.length()); assertEquals(10000, str.length());