]> granicus.if.org Git - python/commitdiff
Issue #28321: Fixed writing non-BMP characters with binary format in plistlib.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 4 Oct 2016 17:04:30 +0000 (20:04 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 4 Oct 2016 17:04:30 +0000 (20:04 +0300)
Lib/plistlib.py
Lib/test/test_plistlib.py
Misc/NEWS

index b66639ca9e59ea18a2cd1e19f9cbd8bbf4268144..2502b39c7c1bfaf55219b5691b70f458eca35e7f 100644 (file)
@@ -918,7 +918,7 @@ class _BinaryPlistWriter (object):
                 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)
 
index 16114f9f6f3e4d6dd715697a418b2642d038d672..692cac4bdf42cc299da03c82718ece97cedd677c 100644 (file)
@@ -361,6 +361,13 @@ class TestPlistlib(unittest.TestCase):
                                   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):
index 8816ea9ead9171aeeaa84cbbaa93a84b3605fe79..ef9ba7fdd8f198c1c3b6747219db268876b11420 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -89,6 +89,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #28321: Fixed writing non-BMP characters with binary format in plistlib.
+
 - Issue #28322: Fixed possible crashes when unpickle itertools objects from
   incorrect pickle data.  Based on patch by John Leitch.