py/lexer: Raise SyntaxError when str hex escape sequence is malformed.
Addresses issue #1390.
This commit is contained in:
parent
f17e663493
commit
d241c2a592
|
@ -454,8 +454,8 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, bool first_token) {
|
||||||
{
|
{
|
||||||
mp_uint_t num = 0;
|
mp_uint_t num = 0;
|
||||||
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
|
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
|
||||||
// TODO error message
|
// not enough hex chars for escape sequence
|
||||||
assert(0);
|
lex->tok_kind = MP_TOKEN_INVALID;
|
||||||
}
|
}
|
||||||
c = num;
|
c = num;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -38,3 +38,21 @@ def a(x):
|
||||||
if x:
|
if x:
|
||||||
print(x)
|
print(x)
|
||||||
a(1)
|
a(1)
|
||||||
|
|
||||||
|
# badly formed hex escape sequences
|
||||||
|
try:
|
||||||
|
exec(r"'\x0'")
|
||||||
|
except SyntaxError:
|
||||||
|
print("SyntaxError")
|
||||||
|
try:
|
||||||
|
exec(r"b'\x0'")
|
||||||
|
except SyntaxError:
|
||||||
|
print("SyntaxError")
|
||||||
|
try:
|
||||||
|
exec(r"'\u000'")
|
||||||
|
except SyntaxError:
|
||||||
|
print("SyntaxError")
|
||||||
|
try:
|
||||||
|
exec(r"'\U0000000'")
|
||||||
|
except SyntaxError:
|
||||||
|
print("SyntaxError")
|
||||||
|
|
Loading…
Reference in New Issue