diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index ae978fb6c9..f0433f5479 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -114,6 +114,10 @@ impl Token { if unicode { let string = input_tendril.to_string(); let unicode_number = &string[3..string.len() - 1]; + let len = unicode_number.len(); + if !(1..=6).contains(&len) { + return None; + } if let Ok(hex) = u32::from_str_radix(&unicode_number, 16) { if let Some(character) = std::char::from_u32(hex) { @@ -122,7 +126,9 @@ impl Token { } } - if let Some(character) = input_tendril.to_string().chars().next() { + if input_tendril.to_string().chars().count() != 1 { + return None; + } else if let Some(character) = input_tendril.to_string().chars().next() { return Some(character); } 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 ae4e3247ba..de7ba436a9 100644 --- a/tests/expectations/parser/parser/expression/literal/char_fail.leo.out +++ b/tests/expectations/parser/parser/expression/literal/char_fail.leo.out @@ -6,3 +6,7 @@ outputs: - " --> test:1:1\n |\n 1 | 'a\n | ^\n |\n = unexpected token: '''" - " --> test:1:1\n |\n 1 | ''\n | ^\n |\n = unexpected token: '''" - " --> test:1:1\n |\n 1 | '\\x9'\n | ^\n |\n = unexpected token: '''" + - " --> 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 | '😭😂😘'\n | ^\n |\n = unexpected token: '''" diff --git a/tests/parser/expression/literal/char_fail.leo b/tests/parser/expression/literal/char_fail.leo index d69ae92ffc..b930d4e5c2 100644 --- a/tests/parser/expression/literal/char_fail.leo +++ b/tests/parser/expression/literal/char_fail.leo @@ -9,4 +9,12 @@ expectation: Fail '' -'\x9' \ No newline at end of file +'\x9' + +'abcdefg' + +'\t\t' + +'\u{bbbbb}\u{aaaa}' + +'😭😂😘' \ No newline at end of file