Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading nested NoopStreams with sharebuf=false produces garbage data #187

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/noop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function fillbuffer(stream::NoopStream; eager::Bool = false)
changemode!(stream, :read)
buffer = stream.buffer1
@assert buffer === stream.buffer2
if stream.stream isa TranscodingStream && buffer === stream.buffer1
if stream.stream isa TranscodingStream && buffer === stream.stream.buffer1
# Delegate the operation when buffers are shared.
return fillbuffer(stream.stream, eager = eager)
end
Expand Down
13 changes: 13 additions & 0 deletions test/codecnoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@
@test read(stream) == b"foobar"
close(stream)

stream = NoopStream(NoopStream(IOBuffer("foobar")); sharedbuf=false)
@test read(stream) == b"foobar"
close(stream)

stream = NoopStream(NoopStream(IOBuffer("foobar")); sharedbuf=false)
@test map(x->read(stream, UInt8), 1:6) == b"foobar"
@test eof(stream)
close(stream)

stream = NoopStream(NoopStream(NoopStream(IOBuffer("foobar")); sharedbuf=false))
@test read(stream) == b"foobar"
close(stream)

# Two buffers are the same object.
stream = NoopStream(IOBuffer("foo"))
@test stream.buffer1 === stream.buffer2
Expand Down
Loading