From 319004a73d8f475d96ffbccfb283a166fb79c3ef Mon Sep 17 00:00:00 2001 From: kkolinko Date: Mon, 17 May 2010 16:28:44 +0000 Subject: [PATCH] Fix a bug in ByteChunk.indexOf(String, ...) The problem is that the method could not find a string which length is 1, as the only successful exit from the method was from inside the loop that checks the second and subsequent characters. I added the testcase for this in r945230. In the test the bc.indexOf("o", 0, 1, 5) call returned -1, instead of 7. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@945231 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/buf/ByteChunk.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/org/apache/tomcat/util/buf/ByteChunk.java b/java/org/apache/tomcat/util/buf/ByteChunk.java index a4fd986e4..53edd4e59 100644 --- a/java/org/apache/tomcat/util/buf/ByteChunk.java +++ b/java/org/apache/tomcat/util/buf/ByteChunk.java @@ -685,15 +685,16 @@ public final class ByteChunk implements Cloneable, Serializable { // Look for first char int srcEnd = srcOff + srcLen; + mainLoop: for( int i=myOff+start; i <= (end - srcLen); i++ ) { if( buff[i] != first ) continue; // found first char, now look for a match int myPos=i+1; for( int srcPos=srcOff + 1; srcPos< srcEnd; ) { if( buff[myPos++] != src.charAt( srcPos++ )) - break; - if( srcPos==srcEnd ) return i-start; // found it + continue mainLoop; } + return i-start; // found it } return -1; } -- 2.11.0