diff -r 3544827d42e6 Lib/_pyio.py --- a/Lib/_pyio.py Tue Jan 28 12:26:24 2014 -0500 +++ b/Lib/_pyio.py Tue Jan 28 22:25:01 2014 +0200 @@ -2052,7 +2052,7 @@ 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 -r 3544827d42e6 Lib/test/test_memoryio.py --- a/Lib/test/test_memoryio.py Tue Jan 28 12:26:24 2014 -0500 +++ b/Lib/test/test_memoryio.py Tue Jan 28 22:25:01 2014 +0200 @@ -609,6 +609,13 @@ UnsupportedOperation = pyio.UnsupportedOperation EOF = "" + def test_lone_surrogates(self): + 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.