Skip to content

Commit db8d626

Browse files
Issue #28321: Fixed writing non-BMP characters with binary format in plistlib.
2 parents 27b4098 + 7338ebc commit db8d626

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
@@ -360,6 +360,13 @@ def test_controlcharacters(self):
360360
plistlib.dumps,
361361
testString)
362362

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

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Core and Builtins
5050
Library
5151
-------
5252

53+
- Issue #28321: Fixed writing non-BMP characters with binary format in plistlib.
54+
5355
- Issue #28225: bz2 module now supports pathlib. Initial patch by Ethan Furman.
5456

5557
- Issue #28227: gzip now supports pathlib. Patch by Ethan Furman.

0 commit comments

Comments
 (0)