Skip to content
Open
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
14 changes: 7 additions & 7 deletions ftfy/bad_codecs/utf8_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@
CESU8_EXPR = (
b"("
b"\xed"
b"([\xa0-\xaf]|$)"
b"([\x80-\xbf]|$)"
b"(\xed|$)"
b"([\xb0-\xbf]|$)"
b"([\x80-\xbf]|$)"
b"([\xa0-\xaf]|\\Z)"
b"([\x80-\xbf]|\\Z)"
b"(\xed|\\Z)"
b"([\xb0-\xbf]|\\Z)"
b"([\x80-\xbf]|\\Z)"
b")"
)

CESU8_RE = re.compile(CESU8_EXPR)

# This expression matches isolated surrogate characters that aren't
# CESU-8, which have to be handled carefully on Python 2.
SURROGATE_EXPR = b"(\xed([\xa0-\xbf]|$)([\x80-\xbf]|$))"
SURROGATE_EXPR = b"(\xed([\xa0-\xbf]|\\Z)([\x80-\xbf]|\\Z))"

# This expression matches the Java encoding of U+0, including if it's
# truncated and we need more bytes.
NULL_EXPR = b"(\xc0(\x80|$))"
NULL_EXPR = b"(\xc0(\x80|\\Z))"

# This regex matches cases that we need to decode differently from
# standard UTF-8.
Expand Down