Reader.peekDelimiterInclusive: Fix handling of stream
implementations that return 0
#25446
+96
−4
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
n
returned fromr.vtable.stream
as the length of the slice to check, but it's valid forvtable.stream
implementations to return 0 if they wrote to the buffer instead ofw
. In that scenario, theindexOfScalarPos
would 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.stream
can both:vtable.stream
implementation to rebase)Also introduces
std.testing.ReaderIndirect
which helps in being able to test against Reader implementations that return 0 fromstream
/readVec
Fixes #25428
Before this PR, the added
"takeDelimiterInclusive on an indirect reader when it rebases"
test would fail witherror.StreamTooLong
since 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
stream
ambiguity 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 bothbuffer
andw
in the samestream
call).(see also #25169 for some extra context around those issues)
The added
"readSliceShort with indirect reader"
test is just to verify thestd.testing.ReaderIndirect
implementation around rebasing withinstream
(without the rebase within stream, that test would enter an infinite loop).