]> granicus.if.org Git - python/commitdiff
Issue #20424: Python implementation of io.StringIO now supports lone surrogates.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 29 Jan 2014 09:33:26 +0000 (11:33 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 29 Jan 2014 09:33:26 +0000 (11:33 +0200)
Lib/_pyio.py
Lib/test/test_memoryio.py
Misc/NEWS

index aab60db4be04ae93c13488ca09a1e951b5a85092..a9b00640f9da9c9aed8813e260dfc17fa2863574 100644 (file)
@@ -2044,7 +2044,7 @@ class StringIO(TextIOWrapper):
     def __init__(self, initial_value="", newline="\n"):
         super(StringIO, self).__init__(BytesIO(),
                                        encoding="utf-8",
-                                       errors="strict",
+                                       errors="surrogatepass",
                                        newline=newline)
         # Issue #5645: make universal newlines semantics the same as in the
         # C version, even under Windows.
index d611a3138b265894b0f571ee7b9208d7ccc9943f..50c91ab20da4ecea4fd1387ed3be65b3acb2c67e 100644 (file)
@@ -609,6 +609,15 @@ class PyStringIOTest(MemoryTestMixin, MemorySeekTestMixin,
     UnsupportedOperation = pyio.UnsupportedOperation
     EOF = ""
 
+    def test_lone_surrogates(self):
+        # Issue #20424
+        memio = self.ioclass('\ud800')
+        self.assertEqual(memio.read(), '\ud800')
+
+        memio = self.ioclass()
+        memio.write('\ud800')
+        self.assertEqual(memio.getvalue(), '\ud800')
+
 
 class PyStringIOPickleTest(TextIOTestMixin, unittest.TestCase):
     """Test if pickle restores properly the internal state of StringIO.
index c52ca189eae6da0124ca47f294c200a8f0325ba8..8b24dc366909a0a029e0af902e56c2b9c650255f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #20424: Python implementation of io.StringIO now supports lone surrogates.
+
 - Issue #19456: ntpath.join() now joins relative paths correctly when a drive
   is present.