Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def end_dict(self):
self.stack.pop()

def end_key(self):
if self.current_key or not isinstance(self.stack[-1], dict):
if (self.current_key or not self.stack
or not isinstance(self.stack[-1], dict)):
raise ValueError("unexpected key at line %d" %
self.parser.CurrentLineNumber)
self.current_key = self.get_data()
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,12 @@ def test_invalidreal(self):
self.assertRaises(ValueError, plistlib.loads,
b"<plist><integer>not real</integer></plist>")

def test_invalidkey(self):
for xml in (b"<plist><key>x</key></plist>",
b'<?xml version="1.0"?><key>x</key>',
b"<plist><array><key>x</key></array></plist>"):
self.assertRaises(ValueError, plistlib.loads, xml)

def test_integer_notations(self):
pl = b"<plist><integer>456</integer></plist>"
value = plistlib.loads(pl)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`plistlib` now raises :exc:`ValueError` for a ``<key>`` outside a
``<dict>`` in an XML plist. Patch by tonghuaroot.
Loading