breken-ai opened a new pull request, #1076:
URL: https://github.com/apache/tomcat/pull/1076

   ## Fix `CharChunk.indexOf(char)` for chunks with a non-zero start
   
   `CharChunk.indexOf(char c)` calls `indexOf(c, start)`, but the second 
argument of `indexOf(char, int)` is relative to the chunk start (it adds 
`start` again). So for a chunk whose `start` is greater than 0, the search 
begins at `2 * start`. A match before that point is missed and the method 
returns -1.
   
   ```java
   char[] chars = "xx=yy=zz".toCharArray();
   CharChunk cc = new CharChunk();
   cc.setChars(chars, 3, 5);   // "yy=zz"
   cc.indexOf('=');            // returns -1, expected 2
   cc.indexOf('=', 0);         // returns 2
   ```
   
   The fix passes `0` instead of `start`. The only in-tree caller 
(`Response.normalize()` on the redirect `CharChunk`) always has `start == 0`, 
so current Tomcat behaviour does not change. The bug only affects other users 
of the public method on offset chunks. The code has been this way since at 
least the 2010 formatting commits.
   
   ### Testing
   
   - Added `TestCharChunk.testIndexOf_Char`. On `main` (2a7e82c) it fails with 
`expected:<2> but was:<-1>`, and it passes with the fix.
   - `ant test -Dtest.name='org/apache/tomcat/util/buf/Test*.java'`: all pass. 
`org.apache.catalina.connector.TestResponse`: 85/85 pass (NIO, JDK 21.0.12).
   - `ant validate -Dexecute.validate=true` (Checkstyle) passes.
   - Added a changelog entry under Coyote.
   
   I wrote this change with help from an AI coding assistant, then reviewed it 
and ran the tests above myself.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to