Reader.peekDelimiterInclusive: Fix handling of stream implementations that return 0
          #25446
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Previously, the logic in peekDelimiterInclusive (when the delimiter was not found in the existing buffer) used the
nreturned fromr.vtable.streamas the length of the slice to check, but it's valid forvtable.streamimplementations to return 0 if they wrote to the buffer instead ofw. In that scenario, theindexOfScalarPoswould be given a 0-length slice so it would never be able to find the delimiter.This commit changes the logic to assume that
r.vtable.streamcan both:vtable.streamimplementation to rebase)Also introduces
std.testing.ReaderIndirectwhich helps in being able to test against Reader implementations that return 0 fromstream/readVecFixes #25428
Before this PR, the added
"takeDelimiterInclusive on an indirect reader when it rebases"test would fail witherror.StreamTooLongsince it'd always be searching for the delimiter in a 0-length slice.This is a very targeted fix. It does not address any of the following:
It also assumes that the
streamambiguity described in #25170 should be resolved in the "writing to w cannot modify the buffer" way (i.e. this fix assumes that no implementation will try to write to bothbufferandwin the samestreamcall).(see also #25169 for some extra context around those issues)
The added
"readSliceShort with indirect reader"test is just to verify thestd.testing.ReaderIndirectimplementation around rebasing withinstream(without the rebase within stream, that test would enter an infinite loop).