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
7 changes: 7 additions & 0 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,13 @@ def test_invalidarray(self):
self.assertRaises(ValueError, plistlib.loads,
("<plist><array>%s</array></plist>"%i).encode())

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>"):
Comment thread
tonghuaroot marked this conversation as resolved.
Resolved
with self.subTest(xml=xml):
self.assertRaises(ValueError, plistlib.loads, xml)

def test_invaliddict(self):
for i in ["<key><true/>k</key><string>compound key</string>",
"<key>single key</key>",
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