changeset: 104285:3a7234d04fe9 branch: 3.6 parent: 104280:4368f897b33e parent: 104284:381ef0f08f89 user: Serhiy Storchaka date: Tue Oct 04 20:08:29 2016 +0300 files: Lib/plistlib.py Lib/test/test_plistlib.py Misc/NEWS description: Issue #28321: Fixed writing non-BMP characters with binary format in plistlib. diff -r 4368f897b33e -r 3a7234d04fe9 Lib/plistlib.py --- a/Lib/plistlib.py Tue Oct 04 18:24:21 2016 +0300 +++ b/Lib/plistlib.py Tue Oct 04 20:08:29 2016 +0300 @@ -918,7 +918,7 @@ self._write_size(0x50, len(value)) except UnicodeEncodeError: t = value.encode('utf-16be') - self._write_size(0x60, len(value)) + self._write_size(0x60, len(t) // 2) self._fp.write(t) diff -r 4368f897b33e -r 3a7234d04fe9 Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py Tue Oct 04 18:24:21 2016 +0300 +++ b/Lib/test/test_plistlib.py Tue Oct 04 20:08:29 2016 +0300 @@ -360,6 +360,13 @@ plistlib.dumps, testString) + def test_non_bmp_characters(self): + pl = {'python': '\U0001f40d'} + for fmt in ALL_FORMATS: + with self.subTest(fmt=fmt): + data = plistlib.dumps(pl, fmt=fmt) + self.assertEqual(plistlib.loads(data), pl) + def test_nondictroot(self): for fmt in ALL_FORMATS: with self.subTest(fmt=fmt): diff -r 4368f897b33e -r 3a7234d04fe9 Misc/NEWS --- a/Misc/NEWS Tue Oct 04 18:24:21 2016 +0300 +++ b/Misc/NEWS Tue Oct 04 20:08:29 2016 +0300 @@ -50,6 +50,8 @@ Library ------- +- Issue #28321: Fixed writing non-BMP characters with binary format in plistlib. + - Issue #28225: bz2 module now supports pathlib. Initial patch by Ethan Furman. - Issue #28227: gzip now supports pathlib. Patch by Ethan Furman.