fix parser bug allowing illegal unicode escape

This commit is contained in:
gluax 2021-06-10 10:59:35 -07:00
parent d6266102c3
commit 5b4cc494c1
3 changed files with 10 additions and 4 deletions

View File

@ -113,6 +113,10 @@ impl Token {
if unicode {
let string = input_tendril.to_string();
if &string[string.len() - 1..] != "}" {
return None;
}
let unicode_number = &string[3..string.len() - 1];
let len = unicode_number.len();
if !(1..=6).contains(&len) {

View File

@ -18,12 +18,14 @@ outputs:
- " --> test:1:1\n |\n 1 | '\\1'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\9'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\*'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\x'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u'\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 | '\\uz'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u1'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u123'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | \\u{2764z'\n | ^\n |\n = unexpected token: '\\'"
- " --> test:1:1\n |\n 1 | \\u{276g}'\n | ^\n |\n = unexpected token: '\\'"
- " --> test:1:1\n |\n 1 | '\\u{2764z'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u{276g}'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u00000000'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u01000000'\n | ^\n |\n = unexpected token: '''"
- " --> test:1:1\n |\n 1 | '\\u9999999'\n | ^\n |\n = unexpected token: '''"

View File

@ -31,8 +31,8 @@ expectation: Fail
'\uz'
'\u1'
'\u123'
\u{2764z'
\u{276g}'
'\u{2764z'
'\u{276g}'
'\u00000000'
'\u01000000'
'\u9999999'