Fixing #LANG-294. The indexOf method did not take into account the size variable that limited the amount of the buffer that should be looked at.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@469677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d8b6f5b5c6
commit
8e52e2169b
|
@ -1773,8 +1773,9 @@ public int indexOf(String str, int startIndex) {
|
|||
return -1;
|
||||
}
|
||||
char[] thisBuf = buffer;
|
||||
int len = size - strLen + 1;
|
||||
outer:
|
||||
for (int i = startIndex; i < thisBuf.length - strLen; i++) {
|
||||
for (int i = startIndex; i < len; i++) {
|
||||
for (int j = 0; j < strLen; j++) {
|
||||
if (str.charAt(j) != thisBuf[i + j]) {
|
||||
continue outer;
|
||||
|
|
|
@ -1728,4 +1728,17 @@ public void testToStringBuffer() {
|
|||
assertEquals(new StringBuffer("junit").toString(), sb.toStringBuffer().toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testLang294() {
|
||||
StrBuilder sb = new StrBuilder("\n%BLAH%\nDo more stuff\neven more stuff\n%BLAH%\n");
|
||||
sb.deleteAll("\n%BLAH%");
|
||||
assertEquals("\nDo more stuff\neven more stuff\n", sb.toString());
|
||||
}
|
||||
|
||||
public void testIndexOfLang294() {
|
||||
StrBuilder sb = new StrBuilder("onetwothree");
|
||||
sb.deleteFirst("three");
|
||||
assertEquals(-1, sb.indexOf("three"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue