From d1eb75585ef4c108732ec815cdc0adef087b1c3e Mon Sep 17 00:00:00 2001 From: "Miss Skeleton (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 20 Oct 2020 01:05:40 -0700 Subject: bpo-41491: plistlib: accept hexadecimal integer values in xml plist files (GH-22764) (GH-22807) (cherry picked from commit 3185267400be853404f22a1e06bb9fe1210735c7) Co-authored-by: Ronald Oussoren Co-authored-by: Ronald Oussoren --- Lib/plistlib.py | 6 +++++- Lib/test/test_plistlib.py | 13 +++++++++++++ .../next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2020-10-19-14-02-09.bpo-41491.d1BUWH.rst diff --git a/Lib/plistlib.py b/Lib/plistlib.py index 533ed13..9813613 100644 --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -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())) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index de1c848..d714880 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -499,6 +499,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 0000000..4f39c91 --- /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 -- cgit v0.12