Kaydet (Commit) d048003d authored tarafından Lars Gustäbel's avatar Lars Gustäbel

Issue #24514: tarfile now tolerates number fields consisting of only whitespace.

üst 97cceac3
...@@ -186,7 +186,7 @@ def nti(s): ...@@ -186,7 +186,7 @@ def nti(s):
# itn() below. # itn() below.
if s[0] != chr(0200): if s[0] != chr(0200):
try: try:
n = int(nts(s) or "0", 8) n = int(nts(s).strip() or "0", 8)
except ValueError: except ValueError:
raise InvalidHeaderError("invalid header") raise InvalidHeaderError("invalid header")
else: else:
......
...@@ -1566,6 +1566,14 @@ class LimitsTest(unittest.TestCase): ...@@ -1566,6 +1566,14 @@ class LimitsTest(unittest.TestCase):
tarinfo.tobuf(tarfile.PAX_FORMAT) 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): class ContextManagerTest(unittest.TestCase):
def test_basic(self): def test_basic(self):
...@@ -1730,6 +1738,7 @@ def test_main(): ...@@ -1730,6 +1738,7 @@ def test_main():
PaxUnicodeTest, PaxUnicodeTest,
AppendTest, AppendTest,
LimitsTest, LimitsTest,
MiscTest,
ContextManagerTest, ContextManagerTest,
] ]
......
...@@ -34,6 +34,9 @@ Core and Builtins ...@@ -34,6 +34,9 @@ Core and Builtins
Library Library
------- -------
- Issue #24514: tarfile now tolerates number fields consisting of only
whitespace.
- Issue #20387: Restore semantic round-trip correctness in tokenize/untokenize - Issue #20387: Restore semantic round-trip correctness in tokenize/untokenize
for tab-indented blocks. for tab-indented blocks.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment