summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/codecs.py4
-rw-r--r--Lib/test/test_codecs.py30
2 files changed, 32 insertions, 2 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index f6d480c..b283925 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -322,9 +322,9 @@ class StreamReader(Codec):
line = line0withend
else:
line = line0withoutend
- break
+ break
# we didn't get anything or this was our only try
- elif not data or size is not None:
+ if not data or size is not None:
if line and not keepends:
line = line.splitlines(False)[0]
break
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 99ed82d..dbe9b88 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -108,6 +108,36 @@ class ReadTest(unittest.TestCase):
writer.write(u"foo\r\n")
self.assertEqual(reader.readline(keepends=True), u"foo\r\n")
+ def test_bug1098990_a(self):
+ s1 = u"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\r\n"
+ s2 = u"offending line: ladfj askldfj klasdj fskla dfzaskdj fasklfj laskd fjasklfzzzzaa%whereisthis!!!\r\n"
+ s3 = u"next line.\r\n"
+
+ s = (s1+s2+s3).encode(self.encoding)
+ stream = StringIO.StringIO(s)
+ reader = codecs.getreader(self.encoding)(stream)
+ self.assertEqual(reader.readline(), s1)
+ self.assertEqual(reader.readline(), s2)
+ self.assertEqual(reader.readline(), s3)
+ self.assertEqual(reader.readline(), u"")
+
+ def test_bug1098990_b(self):
+ s1 = u"aaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ s2 = u"bbbbbbbbbbbbbbbbbbbbbbbb\r\n"
+ s3 = u"stillokay:bbbbxx\r\n"
+ s4 = u"broken!!!!badbad\r\n"
+ s5 = u"againokay.\r\n"
+
+ s = (s1+s2+s3+s4+s5).encode(self.encoding)
+ stream = StringIO.StringIO(s)
+ reader = codecs.getreader(self.encoding)(stream)
+ self.assertEqual(reader.readline(), s1)
+ self.assertEqual(reader.readline(), s2)
+ self.assertEqual(reader.readline(), s3)
+ self.assertEqual(reader.readline(), s4)
+ self.assertEqual(reader.readline(), s5)
+ self.assertEqual(reader.readline(), u"")
+
class UTF16Test(ReadTest):
encoding = "utf-16"