mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
gh-94606: Fix error when message with Unicode surrogate not surrogateescaped string (GH-94641)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
3251ba8f1a
commit
27a5fd8cb8
4 changed files with 49 additions and 16 deletions
|
|
@ -44,10 +44,10 @@ specialsre = re.compile(r'[][\\()<>@,:;".]')
|
|||
escapesre = re.compile(r'[\\"]')
|
||||
|
||||
def _has_surrogates(s):
|
||||
"""Return True if s contains surrogate-escaped binary data."""
|
||||
"""Return True if s may contain surrogate-escaped binary data."""
|
||||
# This check is based on the fact that unless there are surrogates, utf8
|
||||
# (Python's default encoding) can encode any string. This is the fastest
|
||||
# way to check for surrogates, see issue 11454 for timings.
|
||||
# way to check for surrogates, see bpo-11454 (moved to gh-55663) for timings.
|
||||
try:
|
||||
s.encode()
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue