From 729967637c1ead8042bca8e1ece3906f6f6ed6e7 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 10 Jan 2011 17:15:55 -0600 Subject: Tolerate streams with the \r missing from the chunk length. --- python/subunit/chunked.py | 2 +- python/subunit/tests/test_chunked.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/subunit/chunked.py b/python/subunit/chunked.py index 82e4b0d..9c51357 100644 --- a/python/subunit/chunked.py +++ b/python/subunit/chunked.py @@ -87,7 +87,7 @@ class Decoder(object): if count_chars[-1][-1] != '\n': return count_str = ''.join(count_chars) - self.body_length = int(count_str[:-2], 16) + self.body_length = int(count_str.rstrip('\n\r'), 16) excess_bytes = len(count_str) while excess_bytes: if excess_bytes >= len(self.buffered_bytes[0]): diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index a24e31e..681af6b 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -1,6 +1,7 @@ # # subunit: extensions to python unittest to get test results from subprocesses. # Copyright (C) 2005 Robert Collins +# Copyright (C) 2011 Martin Pool # # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the @@ -86,6 +87,13 @@ class TestDecode(unittest.TestCase): self.assertEqual('', self.decoder.write('0\r\n')) self.assertEqual('1' * 65536 + '2' * 65536, self.output.getvalue()) + def test_decode_newline(self): + """Tolerate chunk markers with no cr character.""" + self.assertEqual(None, self.decoder.write('a\n')) + self.assertEqual(None, self.decoder.write('abcdeabcde')) + self.assertEqual(None, self.decoder.write('0\n')) + self.assertEqual('abcdeabcde', self.output.getvalue()) + class TestEncode(unittest.TestCase): -- cgit v1.2.1