Kaydet (Commit) 326edfde authored tarafından Ronald Oussoren's avatar Ronald Oussoren

Ensure that plistlib doesn't corrupt deeply nested datastructures

Without this changeset plistlib would write empty tags for plistlib.Data
objects in deeply nested datastructures.

Fixes #17353
üst d638381e
......@@ -228,8 +228,8 @@ class PlistWriter(DumbXMLWriter):
def writeData(self, data):
self.beginElement("data")
self.indentLevel -= 1
maxlinelength = 76 - len(self.indent.replace(b"\t", b" " * 8) *
self.indentLevel)
maxlinelength = max(16, 76 - len(self.indent.replace(b"\t", b" " * 8) *
self.indentLevel))
for line in data.asBase64(maxlinelength).split(b"\n"):
if line:
self.writeln(line)
......
......@@ -141,6 +141,18 @@ class TestPlistlib(unittest.TestCase):
data2 = plistlib.writePlistToBytes(pl2)
self.assertEqual(data, data2)
def test_indentation_array(self):
data = [[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]]
self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data)
def test_indentation_dict(self):
data = {'1': {'2': {'3': {'4': {'5': {'6': {'7': {'8': {'9': plistlib.Data(b'aaaaaa')}}}}}}}}}
self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data)
def test_indentation_dict_mix(self):
data = {'1': {'2': [{'3': [[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]}]}}
self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data)
def test_appleformatting(self):
pl = plistlib.readPlistFromBytes(TESTDATA)
data = plistlib.writePlistToBytes(pl)
......
......@@ -36,6 +36,8 @@ Core and Builtins
Library
-------
- Issue #17353: Plistlib emitted empty data tags with deeply nested datastructures
- Issue #11714: Use 'with' statements to assure a Semaphore releases a
condition variable. Original patch by Thomas Rachel.
......
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