[Python-checkins] bpo-41491: plistlib: accept hexadecimal integer values in xml plist files (GH-22764) (GH-22806)

Miss Skeleton (bot) webhook-mailer at python.org
Tue Oct 20 04:05:26 EDT 2020


https://github.com/python/cpython/commit/3fc7080220b8dd2e1b067b3224879133d895ea80
commit: 3fc7080220b8dd2e1b067b3224879133d895ea80
branch: 3.9
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-10-20T10:05:21+02:00
summary:

bpo-41491: plistlib: accept hexadecimal integer values in xml plist files (GH-22764) (GH-22806)

(cherry picked from commit 3185267400be853404f22a1e06bb9fe1210735c7)

Co-authored-by: Ronald Oussoren <ronaldoussoren at mac.com>

files:
A Misc/NEWS.d/next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst
M Lib/plistlib.py
M Lib/test/test_plistlib.py

diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index ba7ac1936479f..a7403510a3216 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -252,7 +252,11 @@ def end_false(self):
         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()))
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index 7cc6bad4235cc..f821e1da77484 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -497,6 +497,19 @@ def test_invalidreal(self):
         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
index 0000000000000..4f39c91b284fa
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst
@@ -0,0 +1 @@
+plistlib: fix parsing XML plists with hexadecimal integer values



More information about the Python-checkins mailing list