]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41491: plistlib: accept hexadecimal integer values in xml plist files (GH-22764...
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 20 Oct 2020 08:05:40 +0000 (01:05 -0700)
committerGitHub <noreply@github.com>
Tue, 20 Oct 2020 08:05:40 +0000 (10:05 +0200)
(cherry picked from commit 3185267400be853404f22a1e06bb9fe1210735c7)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Lib/plistlib.py
Lib/test/test_plistlib.py
Misc/NEWS.d/next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst [new file with mode: 0644]

index 533ed1351f135772d3702363b080877141a838cb..9813613ff153b3e66946ce7532e50854e5ed71ff 100644 (file)
@@ -364,7 +364,11 @@ class _PlistParser:
         self.add_object(False)
 
     def end_integer(self):
-        self.add_object(int(self.get_data()))
+        raw = self.get_data()
+        if raw.startswith('0x') or raw.startswith('0X'):
+            self.add_object(int(raw, 16))
+        else:
+            self.add_object(int(raw))
 
     def end_real(self):
         self.add_object(float(self.get_data()))
index de1c848ae265f9d84fb97f45915ca67555fd60db..d714880a7dd250bfcc0c143f7edca532adf9d1ab 100644 (file)
@@ -499,6 +499,19 @@ class TestPlistlib(unittest.TestCase):
         self.assertRaises(ValueError, plistlib.loads,
                           b"<plist><integer>not real</integer></plist>")
 
+    def test_integer_notations(self):
+        pl = b"<plist><integer>456</integer></plist>"
+        value = plistlib.loads(pl)
+        self.assertEqual(value, 456)
+
+        pl = b"<plist><integer>0xa</integer></plist>"
+        value = plistlib.loads(pl)
+        self.assertEqual(value, 10)
+
+        pl = b"<plist><integer>0123</integer></plist>"
+        value = plistlib.loads(pl)
+        self.assertEqual(value, 123)
+
     def test_xml_encodings(self):
         base = TESTDATA[plistlib.FMT_XML]
 
diff --git a/Misc/NEWS.d/next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst b/Misc/NEWS.d/next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst
new file mode 100644 (file)
index 0000000..4f39c91
--- /dev/null
@@ -0,0 +1 @@
+plistlib: fix parsing XML plists with hexadecimal integer values