diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java b/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java index f429e48ad52..e08f92385f3 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java @@ -153,10 +153,10 @@ public class SearchPattern if(data[i] == pattern[i+matched]) matchedCount++; else - break; + return 0; } - return matchedCount; + return matched + matchedCount; } /** diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/SearchPatternTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/SearchPatternTest.java index cfd15a80e07..ba75a702f7a 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/SearchPatternTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/SearchPatternTest.java @@ -143,14 +143,12 @@ public class SearchPatternTest SearchPattern sp = SearchPattern.compile(p); Assert.assertEquals(18,sp.match(d,0,d.length)); Assert.assertEquals(-1,sp.match(d,19,d.length-19)); - Assert.assertEquals(18,sp.startsWith(d,0,d.length,8)); + Assert.assertEquals(26,sp.startsWith(d,0,d.length,8)); p = new String("abcdefghijklmnopqrstuvwxyz").getBytes(StandardCharsets.US_ASCII); - d = new String("ijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz").getBytes(StandardCharsets.US_ASCII); + d = new String("ijklmnopqrstuvwxyNOMATCH").getBytes(StandardCharsets.US_ASCII); sp = SearchPattern.compile(p); - Assert.assertEquals(19,sp.match(d,0,d.length)); - Assert.assertEquals(-1,sp.match(d,20,d.length-20)); - Assert.assertEquals(18,sp.startsWith(d,0,d.length,8)); + Assert.assertEquals(0,sp.startsWith(d,0,d.length,8)); p = new String("abcdefghijklmnopqrstuvwxyz").getBytes(StandardCharsets.US_ASCII); d = new String("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz").getBytes(StandardCharsets.US_ASCII); @@ -167,6 +165,6 @@ public class SearchPatternTest p = new String("abcdefghijklmnopqrstuvwxyz").getBytes(StandardCharsets.US_ASCII); d = new String("mnopqrs").getBytes(StandardCharsets.US_ASCII); sp = SearchPattern.compile(p); - Assert.assertEquals(7,sp.startsWith(d,0,d.length,12)); + Assert.assertEquals(19,sp.startsWith(d,0,d.length,12)); } }