summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pyio.py2
-rw-r--r--Lib/test/test_memoryio.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index d6eee79..edfb9b9 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -2052,7 +2052,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.
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index 4de4f65..d4135d5 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -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.