diff options
| author | Martin Pool <mbp@canonical.com> | 2011-01-10 17:15:55 -0600 |
|---|---|---|
| committer | Martin Pool <mbp@canonical.com> | 2011-01-10 17:15:55 -0600 |
| commit | 729967637c1ead8042bca8e1ece3906f6f6ed6e7 (patch) | |
| tree | 7b5dee431589efc4ad426537e85830cc39b5b282 /python/subunit | |
| parent | d7ae295931962ad4150aeef4d55b5bffebdca87c (diff) | |
| download | subunit-git-729967637c1ead8042bca8e1ece3906f6f6ed6e7.tar.gz | |
Tolerate streams with the \r missing from the chunk length.
Diffstat (limited to 'python/subunit')
| -rw-r--r-- | python/subunit/chunked.py | 2 | ||||
| -rw-r--r-- | python/subunit/tests/test_chunked.py | 8 |
2 files changed, 9 insertions, 1 deletions
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 <robertc@robertcollins.net> +# Copyright (C) 2011 Martin Pool <mbp@sourcefrog.net> # # 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): |
