Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion 9 Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
# syntax classes
SYNTAX_WHITESPACE, SYNTAX_WORD, SYNTAX_SYMBOL = range(3)

def normalize_surrogates(s: str) -> str:
# Encode with surrogatepass, decode to normalize surrogate pairs
try:
return s.encode('utf-16', 'surrogatepass').decode('utf-16')
except UnicodeEncodeError:
return s # fallback if encoding somehow fails

def make_default_syntax_table() -> dict[str, int]:
# XXX perhaps should use some unicodedata here?
Expand Down Expand Up @@ -759,4 +765,5 @@ def bind(self, spec: KeySpec, command: CommandName) -> None:

def get_unicode(self) -> str:
"""Return the current buffer as a unicode string."""
return "".join(self.buffer)
text = "".join(self.buffer)
return normalize_surrogates(text)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash in the REPL on Windows when typing Unicode characters outside the Basic Multilingual Plane (≥ U+10000), such as emoji. These characters are now properly handled as surrogate pairs.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.