Skip to content
Open
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
9 changes: 9 additions & 0 deletions Lib/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ def read(self, size=-1, chars=-1, firstline=False):
self.charbuffer += newchars
# there was no data available
if not newdata:
# The stream is exhausted. If there are leftover bytes in
# bytebuffer, they form an incomplete character. Decode them
# now so that the error handler is applied (strict raises,
# replace emits the replacement character, ignore drops them).
if self.bytebuffer:
newchars, decodedbytes = self.decode(
self.bytebuffer, self.errors)
self.bytebuffer = self.bytebuffer[decodedbytes:]
self.charbuffer += newchars
break
if chars < 0:
# Return everything we've got
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix codecs.StreamReader.read() silently dropping an incomplete character at the end of the stream.
Loading