Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f2e46d

Browse files
Issue #20424: Python implementation of io.StringIO now supports lone surrogates.
2 parents 61f5616 + c92ea76 commit 9f2e46d

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/_pyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ class StringIO(TextIOWrapper):
20522052
def __init__(self, initial_value="", newline="\n"):
20532053
super(StringIO, self).__init__(BytesIO(),
20542054
encoding="utf-8",
2055-
errors="strict",
2055+
errors="surrogatepass",
20562056
newline=newline)
20572057
# Issue #5645: make universal newlines semantics the same as in the
20582058
# C version, even under Windows.

Lib/test/test_memoryio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ class PyStringIOTest(MemoryTestMixin, MemorySeekTestMixin,
609609
UnsupportedOperation = pyio.UnsupportedOperation
610610
EOF = ""
611611

612+
def test_lone_surrogates(self):
613+
# Issue #20424
614+
memio = self.ioclass('\ud800')
615+
self.assertEqual(memio.read(), '\ud800')
616+
617+
memio = self.ioclass()
618+
memio.write('\ud800')
619+
self.assertEqual(memio.getvalue(), '\ud800')
620+
612621

613622
class PyStringIOPickleTest(TextIOTestMixin, unittest.TestCase):
614623
"""Test if pickle restores properly the internal state of StringIO.

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #20424: Python implementation of io.StringIO now supports lone surrogates.
17+
1618
- Issue #20308: inspect.signature now works on classes without user-defined
1719
__init__ or __new__ methods.
1820

0 commit comments

Comments
 (0)