diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2013-04-23 11:47:22 (GMT) |
---|---|---|
committer | Ronald Oussoren <ronaldoussoren@mac.com> | 2013-04-23 11:47:22 (GMT) |
commit | 326edfde560410c8e92545e301722161b657db30 (patch) | |
tree | 907d2343844701c9a1523785044e52126921d19e /Lib | |
parent | d638381ee0f62dd5df85de1fbdc93cb665347eae (diff) | |
download | cpython-326edfde560410c8e92545e301722161b657db30.zip cpython-326edfde560410c8e92545e301722161b657db30.tar.gz cpython-326edfde560410c8e92545e301722161b657db30.tar.bz2 |
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
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/plistlib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_plistlib.py | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py index 41fd8f2..2b0b634 100644 --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -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) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index a9e343e..9e86b3d 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -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) |