Skip to content

Commit 7338ebc

Browse files
Issue #28321: Fixed writing non-BMP characters with binary format in plistlib.
1 parent 7fd9f4b commit 7338ebc

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/plistlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def _write_object(self, value):
918918
self._write_size(0x50, len(value))
919919
except UnicodeEncodeError:
920920
t = value.encode('utf-16be')
921-
self._write_size(0x60, len(value))
921+
self._write_size(0x60, len(t) // 2)
922922

923923
self._fp.write(t)
924924

Lib/test/test_plistlib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ def test_controlcharacters(self):
361361
plistlib.dumps,
362362
testString)
363363

364+
def test_non_bmp_characters(self):
365+
pl = {'python': '\U0001f40d'}
366+
for fmt in ALL_FORMATS:
367+
with self.subTest(fmt=fmt):
368+
data = plistlib.dumps(pl, fmt=fmt)
369+
self.assertEqual(plistlib.loads(data), pl)
370+
364371
def test_nondictroot(self):
365372
for fmt in ALL_FORMATS:
366373
with self.subTest(fmt=fmt):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Core and Builtins
8989
Library
9090
-------
9191

92+
- Issue #28321: Fixed writing non-BMP characters with binary format in plistlib.
93+
9294
- Issue #28322: Fixed possible crashes when unpickle itertools objects from
9395
incorrect pickle data. Based on patch by John Leitch.
9496

0 commit comments

Comments
 (0)