bpo-41491: plistlib: accept hexadecimal integer values in xml plist files (GH-22764) (GH-22807)
(cherry picked from commit 3185267400
)
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
This commit is contained in:
parent
e7c5a43984
commit
d1eb75585e
|
@ -364,7 +364,11 @@ class _PlistParser:
|
||||||
self.add_object(False)
|
self.add_object(False)
|
||||||
|
|
||||||
def end_integer(self):
|
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):
|
def end_real(self):
|
||||||
self.add_object(float(self.get_data()))
|
self.add_object(float(self.get_data()))
|
||||||
|
|
|
@ -499,6 +499,19 @@ class TestPlistlib(unittest.TestCase):
|
||||||
self.assertRaises(ValueError, plistlib.loads,
|
self.assertRaises(ValueError, plistlib.loads,
|
||||||
b"<plist><integer>not real</integer></plist>")
|
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):
|
def test_xml_encodings(self):
|
||||||
base = TESTDATA[plistlib.FMT_XML]
|
base = TESTDATA[plistlib.FMT_XML]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
plistlib: fix parsing XML plists with hexadecimal integer values
|
Loading…
Reference in New Issue