changeset: 96753:301d7efac3de branch: 2.7 parent: 96740:b295b2286697 user: Lars Gustäbel date: Thu Jul 02 19:37:08 2015 +0200 files: Lib/tarfile.py Lib/test/test_tarfile.py Misc/NEWS description: Issue #24514: tarfile now tolerates number fields consisting of only whitespace. diff -r b295b2286697 -r 301d7efac3de Lib/tarfile.py --- a/Lib/tarfile.py Wed Jul 01 11:29:34 2015 -0400 +++ b/Lib/tarfile.py Thu Jul 02 19:37:08 2015 +0200 @@ -186,7 +186,7 @@ # itn() below. if s[0] != chr(0200): try: - n = int(nts(s) or "0", 8) + n = int(nts(s).strip() or "0", 8) except ValueError: raise InvalidHeaderError("invalid header") else: diff -r b295b2286697 -r 301d7efac3de Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py Wed Jul 01 11:29:34 2015 -0400 +++ b/Lib/test/test_tarfile.py Thu Jul 02 19:37:08 2015 +0200 @@ -1566,6 +1566,14 @@ tarinfo.tobuf(tarfile.PAX_FORMAT) +class MiscTest(unittest.TestCase): + + def test_read_number_fields(self): + # Issue 24514: Test if empty number fields are converted to zero. + self.assertEqual(tarfile.nti("\0"), 0) + self.assertEqual(tarfile.nti(" \0"), 0) + + class ContextManagerTest(unittest.TestCase): def test_basic(self): @@ -1730,6 +1738,7 @@ PaxUnicodeTest, AppendTest, LimitsTest, + MiscTest, ContextManagerTest, ] diff -r b295b2286697 -r 301d7efac3de Misc/NEWS --- a/Misc/NEWS Wed Jul 01 11:29:34 2015 -0400 +++ b/Misc/NEWS Thu Jul 02 19:37:08 2015 +0200 @@ -34,6 +34,9 @@ Library ------- +- Issue #24514: tarfile now tolerates number fields consisting of only + whitespace. + - Issue #20387: Restore semantic round-trip correctness in tokenize/untokenize for tab-indented blocks.