diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 775956bf62..b21cc77755 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -299,7 +299,11 @@ impl Token { if input[i] == b'x' { hex = true; } else if input[i] == b'u' { - unicode = true; + if input[i + 1] == b'{' { + unicode = true; + } else { + return (0, None); + } } else { escaped = true; } diff --git a/tests/expectations/parser/parser/expression/literal/char_fail.leo.out b/tests/expectations/parser/parser/expression/literal/char_fail.leo.out index de7ba436a9..5d8c93d1d4 100644 --- a/tests/expectations/parser/parser/expression/literal/char_fail.leo.out +++ b/tests/expectations/parser/parser/expression/literal/char_fail.leo.out @@ -9,4 +9,9 @@ outputs: - " --> test:1:1\n |\n 1 | 'abcdefg'\n | ^\n |\n = unexpected token: '''" - " --> test:1:1\n |\n 1 | '\\t\\t'\n | ^\n |\n = unexpected token: '''" - " --> test:1:1\n |\n 1 | '\\u{bbbbb}\\u{aaaa}'\n | ^\n |\n = unexpected token: '''" + - " --> test:1:1\n |\n 1 | '\\u123'\n | ^\n |\n = unexpected token: '''" + - " --> test:1:1\n |\n 1 | '\\u1' // panic\n | ^\n |\n = unexpected token: '''" + - " --> test:1:1\n |\n 1 | '\\u00000000' // should error\n | ^\n |\n = unexpected token: '''" + - " --> test:1:1\n |\n 1 | '\\u01000000' // should error\n | ^\n |\n = unexpected token: '''" + - " --> test:1:1\n |\n 1 | '\\u9999999' // should error\n | ^\n |\n = unexpected token: '''" - " --> test:1:1\n |\n 1 | '😭😂😘'\n | ^\n |\n = unexpected token: '''" diff --git a/tests/parser/expression/literal/char_fail.leo b/tests/parser/expression/literal/char_fail.leo index b930d4e5c2..aa5bb198f2 100644 --- a/tests/parser/expression/literal/char_fail.leo +++ b/tests/parser/expression/literal/char_fail.leo @@ -17,4 +17,11 @@ expectation: Fail '\u{bbbbb}\u{aaaa}' -'😭😂😘' \ No newline at end of file +'\u123' + +'\u1' // should error +'\u00000000' // should error +'\u01000000' // should error +'\u9999999' // should error + +'😭😂😘'