diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 232009fb939..300dd5a2429 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -158,7 +158,7 @@ class StringIO: newpos = self.len else: newpos = i+1 - if length is not None: + if length is not None and length > 0: if self.pos + length < newpos: newpos = self.pos + length r = self.buf[self.pos:newpos] diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index 58cbec06f85..81f81e58aef 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -28,6 +28,8 @@ class TestGenericStringIO(unittest.TestCase): eq(self._fp.read(10), self._line[:10]) eq(self._fp.readline(), self._line[10:] + '\n') eq(len(self._fp.readlines(60)), 2) + self._fp.seek(0) + eq(self._fp.readline(-1), self._line + '\n') def test_writes(self): f = self.MODULE.StringIO() diff --git a/Misc/NEWS b/Misc/NEWS index d9cb038f819..a933f625849 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -35,6 +35,9 @@ Core and Builtins Library ------- +- Issue #7348: StringIO.StringIO.readline(-1) now acts as if it got no argument + like other file objects. + - Issue #5949: fixed IMAP4_SSL hang when the IMAP server response is missing proper end-of-line termination.