diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index 1752ccd70..4fee5f51c 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -674,7 +674,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ public int indexOf(TString str, int fromIndex) { int sz = length - str.length(); - outer: for (int i = fromIndex; i < sz; ++i) { + outer: for (int i = fromIndex; i <= sz; ++i) { for (int j = 0; j < str.length(); ++j) { if (buffer[i + j] != str.charAt(j)) { continue outer; diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java index dc95c9f9f..aab08bacf 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java @@ -407,4 +407,14 @@ public class StringBuilderTest { public void substringWithUpperBoundAtEndWorks() { assertEquals("23", "123".substring(1, 3)); } + + @Test + public void indexOf() { + StringBuilder sb = new StringBuilder(); + sb.append("12345"); + assertEquals(3, sb.indexOf("45")); + assertEquals(-1, sb.indexOf("56")); + assertEquals(0, sb.indexOf("12345")); + assertEquals(0, sb.indexOf("123")); + } }