summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_plistlib.py
diff options
context:
space:
mode:
authorNed Deily <nad@acm.org>2011-05-28 10:09:33 (GMT)
committerNed Deily <nad@acm.org>2011-05-28 10:09:33 (GMT)
commit59a333844a8a864ef4d41524e931a641ec59f00f (patch)
tree3887db28f955098b942d4b0e2268e484645632a1 /Lib/test/test_plistlib.py
parent61be422bd73784615249d3dfe28c0a8f322b5d65 (diff)
parent32b5cb0a66956785275c62e1d20b6e5ee4241079 (diff)
downloadcpython-59a333844a8a864ef4d41524e931a641ec59f00f.zip
cpython-59a333844a8a864ef4d41524e931a641ec59f00f.tar.gz
cpython-59a333844a8a864ef4d41524e931a641ec59f00f.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)