Aryan Ganjoo created TEXT-243:
---------------------------------

             Summary: StringSubstitutorReader.skip advances the template, not 
the substituted output
                 Key: TEXT-243
                 URL: https://issues.apache.org/jira/browse/TEXT-243
             Project: Commons Text
          Issue Type: Bug
            Reporter: Aryan Ganjoo


h3. Observed

{{StringSubstitutorReader}} inherits {{FilterReader.skip(long)}}, which skips 
characters in the wrapped template reader rather than in the substituted 
output. For example, with template {{${v}Z}} and {{v = abc}}, {{skip(1)}} 
reports one skipped character but the next output is {{{v}Z}} instead of 
{{bcZ}}. Buffered output and substitutions that contract the stream also give 
incorrect skip positions or counts.

h3. Expected

{{skip(n)}} should consume up to {{n}} characters of the stream returned by 
this reader, consistent with the {{Reader.skip}} contract. It should not call 
{{skip}} on the wrapped template reader.

h3. Reproduction and validation

A local test using {{new StringSubstitutorReader(new StringReader("${v}Z"), new 
StringSubstitutor(Collections.singletonMap("v", "abc")))}} reproduces the 
mismatch. The affected production code is unchanged on current Commons Text 
master {{f5bec9dd7becc3a20f3e949fb2391456a94611c3}}. An earlier pristine-source 
regression run had 10 failures among 14 new cases. A local corrected candidate 
passes 18 focused skip tests and the default Maven build (2,007 tests, zero 
failures/errors, three skips); a separate independent read-only review found no 
concrete P1/P2 issue. Java 8, hosted CI, and downstream usage were not tested.

h3. Possible fix

Implement {{skip(long)}} by consuming the substituted output through this 
reader’s {{read}} path, and reject use after the wrapper is closed. This is a 
local candidate, not a submitted PR. AI assistance was used for discovery, test 
and patch preparation, and validation.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to