Skip to content

Commit

Permalink
Ensure that plistlib doesn't corrupt deeply nested datastructures
Browse files Browse the repository at this point in the history
Without this changeset plistlib would write empty tags for plistlib.Data
objects in deeply nested datastructures.

Fixes python#17353
  • Loading branch information
ronaldoussoren committed Apr 23, 2013
1 parent d638381 commit 326edfd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def writeValue(self, value):
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)
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ def test_bytes(self):
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)
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 326edfd

Please sign in to comment.