summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_plistlib.py
diff options
context:
space:
mode:
authorNed Deily <nad@acm.org>2011-05-28 10:02:30 (GMT)
committerNed Deily <nad@acm.org>2011-05-28 10:02:30 (GMT)
commit32b5cb0a66956785275c62e1d20b6e5ee4241079 (patch)
tree2c830d489ec2d9fc76c930089a119fe7744a7824 /Lib/test/test_plistlib.py
parent056f5b9dadd834c26fc6deb87a831b6a3d9f4bf7 (diff)
parentb8e59f77e65ba4caeda8d910bd66df01a468cbea (diff)
downloadcpython-32b5cb0a66956785275c62e1d20b6e5ee4241079.zip
cpython-32b5cb0a66956785275c62e1d20b6e5ee4241079.tar.gz
cpython-32b5cb0a66956785275c62e1d20b6e5ee4241079.tar.bz2
Issue #985064: Make plistlib more resilient to faulty input plists.
Patch by Mher Movsisyan.
Diffstat (limited to 'Lib/test/test_plistlib.py')
-rw-r--r--Lib/test/test_plistlib.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index dfa4725..5f980d0 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -175,6 +175,32 @@ class TestPlistlib(unittest.TestCase):
self.assertEqual(test1, result1)
self.assertEqual(test2, result2)
+ def test_invalidarray(self):
+ for i in ["<key>key inside an array</key>",
+ "<key>key inside an array2</key><real>3</real>",
+ "<true/><key>key inside an array3</key>"]:
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ ("<plist><array>%s</array></plist>"%i).encode())
+
+ def test_invaliddict(self):
+ for i in ["<key><true/>k</key><string>compound key</string>",
+ "<key>single key</key>",
+ "<string>missing key</string>",
+ "<key>k1</key><string>v1</string><real>5.3</real>"
+ "<key>k1</key><key>k2</key><string>double key</string>"]:
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ ("<plist><dict>%s</dict></plist>"%i).encode())
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ ("<plist><array><dict>%s</dict></array></plist>"%i).encode())
+
+ def test_invalidinteger(self):
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ b"<plist><integer>not integer</integer></plist>")
+
+ def test_invalidreal(self):
+ self.assertRaises(ValueError, plistlib.readPlistFromBytes,
+ b"<plist><integer>not real</integer></plist>")
+
def test_main():
support.run_unittest(TestPlistlib)