Skip to content

Commit 7c85c7c

Browse files
committed
py/unicode: Fix check for valid utf8 being stricter about contn chars.
1 parent d63ef86 commit 7c85c7c

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

py/unicode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ bool utf8_check(const byte *p, size_t len) {
180180
for (; p < end; p++) {
181181
byte c = *p;
182182
if (need) {
183-
if (c >= 0x80) {
183+
if (UTF8_IS_CONT(c)) {
184184
need--;
185185
} else {
186186
// mismatch

tests/unicode/unicode.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@
4747
str(bytearray(b'ab\xc0a'), 'utf8')
4848
except UnicodeError:
4949
print('UnicodeError')
50+
try:
51+
str(b'\xf0\xe0\xed\xe8', 'utf8')
52+
except UnicodeError:
53+
print('UnicodeError')

0 commit comments

Comments
 (0)