This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new a44b0802ec Fix CharChunk.indexOf(char) for chunks with a non-zero start
a44b0802ec is described below

commit a44b0802ecb3dd847142153be19ee492ea8541ef
Author: breken-ai <[email protected]>
AuthorDate: Tue Sep 29 19:59:27 2026 -0700

    Fix CharChunk.indexOf(char) for chunks with a non-zero start
    
    indexOf(char) passed the absolute start offset to indexOf(char, int),
    whose starting argument is relative to the chunk start. The search
    therefore began at twice the start offset, so a match before that point
    was missed and -1 was returned. Pass 0 instead.
    
    Generated-by: Claude Code (Claude Opus 5.5)
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 java/org/apache/tomcat/util/buf/CharChunk.java     |  2 +-
 test/org/apache/tomcat/util/buf/TestCharChunk.java | 18 ++++++++++++++++++
 webapps/docs/changelog.xml                         |  5 +++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/buf/CharChunk.java 
b/java/org/apache/tomcat/util/buf/CharChunk.java
index a872f33d58..78722280d7 100644
--- a/java/org/apache/tomcat/util/buf/CharChunk.java
+++ b/java/org/apache/tomcat/util/buf/CharChunk.java
@@ -655,7 +655,7 @@ public final class CharChunk extends AbstractChunk 
implements CharSequence {
      * @return the index of the character, or -1 if not found
      */
     public int indexOf(char c) {
-        return indexOf(c, start);
+        return indexOf(c, 0);
     }
 
 
diff --git a/test/org/apache/tomcat/util/buf/TestCharChunk.java 
b/test/org/apache/tomcat/util/buf/TestCharChunk.java
index c2182af8f1..6a118c27ad 100644
--- a/test/org/apache/tomcat/util/buf/TestCharChunk.java
+++ b/test/org/apache/tomcat/util/buf/TestCharChunk.java
@@ -64,6 +64,24 @@ public class TestCharChunk {
     }
 
 
+    @Test
+    public void testIndexOf_Char() {
+        char[] chars = "xx=yy=zz".toCharArray();
+
+        CharChunk cc = new CharChunk();
+        cc.setChars(chars, 0, chars.length);
+        Assert.assertEquals(2, cc.indexOf('='));
+        Assert.assertEquals(5, cc.indexOf('=', 3));
+
+        // Chunk that does not start at the beginning of the buffer
+        cc.setChars(chars, 3, 5);
+        Assert.assertEquals(2, cc.indexOf('='));
+        Assert.assertEquals(2, cc.indexOf('=', 0));
+        Assert.assertEquals(0, cc.indexOf('y'));
+        Assert.assertEquals(-1, cc.indexOf('x'));
+    }
+
+
     @Test
     public void testToString() {
         CharChunk cc = new CharChunk();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 8acc3525b2..bc88be1694 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -349,6 +349,11 @@
         Ensure that the non-blocking write buffer is empty before sending an 
AJP
         end response message. (markt)
       </fix>
+      <fix>
+        Fix <code>CharChunk.indexOf(char)</code> so that it searches from the
+        start of the chunk rather than from twice the chunk's start offset
+        when the chunk does not begin at the start of its buffer. (breken-ai)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to