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

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


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

commit d098f3226109a49946f1d32b71f52f0083fbaf0e
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)
---
 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 124acaf6f8..aa91b1df32 100644
--- a/java/org/apache/tomcat/util/buf/CharChunk.java
+++ b/java/org/apache/tomcat/util/buf/CharChunk.java
@@ -653,7 +653,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 5aa7115ca9..4c40dd800a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -4411,6 +4411,11 @@
         Skip the write notification in these cases since it would be useless.
         (remm)
       </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