diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index ba7ac193647..a7403510a32 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -252,7 +252,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()))
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index cb071da1f33..c9dce0047b7 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -498,6 +498,19 @@ class TestPlistlib(unittest.TestCase):
self.assertRaises(ValueError, plistlib.loads,
b"not real")
+ def test_integer_notations(self):
+ pl = b"456"
+ value = plistlib.loads(pl)
+ self.assertEqual(value, 456)
+
+ pl = b"0xa"
+ value = plistlib.loads(pl)
+ self.assertEqual(value, 10)
+
+ pl = b"0123"
+ 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 00000000000..4f39c91b284
--- /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