Fix and test for SF bug #1098990: codec readline() splits lines apart.
This commit is contained in:
parent
c0b194a770
commit
9fa0946771
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue