Skip to content

Commit 0be3c70

Browse files
committed
py/lexer: Raise SyntaxError when unicode char point out of range.
1 parent 081f932 commit 0be3c70

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

py/lexer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, bool first_token) {
500500
}
501501
#endif
502502
else {
503-
assert(!"TODO: Throw an error, invalid escape code probably");
503+
// unicode character out of range
504+
// this raises a generic SyntaxError; could provide more info
505+
lex->tok_kind = MP_TOKEN_INVALID;
504506
}
505507
}
506508
} else {

tests/unicode/unicode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@
2020
# printing of unicode chars using repr
2121
# TODO we don't do this correctly
2222
#print(repr(s))
23+
24+
# test invalid escape code
25+
try:
26+
eval('"\\U00110000"')
27+
except SyntaxError:
28+
print('SyntaxError')

0 commit comments

Comments
 (0)