Merge pull request #996 from AleoHQ/fix-unicode-escapes

[Bug] More strict rule for unicode escapes in char and string
This commit is contained in:
Alessandro Coglio 2021-06-03 23:16:40 -07:00 committed by GitHub
commit c67ef6a3b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 6 deletions

View File

@ -162,6 +162,6 @@ pub(crate) fn char_from_input<'a, F: PrimeField, G: GroupType<F>, CS: Constraint
impl<F: PrimeField + std::fmt::Display> std::fmt::Display for Char<F> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.character)
write!(f, "{}", char::escape_default(self.character))
}
}

View File

@ -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;
}

View File

@ -21,13 +21,13 @@ outputs:
registers:
r:
type: char
value:
value: "\\u{2764}"
- input_file: inputs/escaped.in
output:
registers:
r:
type: char
value: "'"
value: "\\'"
- input_file: inputs/hex.in
output:
registers:
@ -39,4 +39,4 @@ outputs:
registers:
r:
type: char
value:
value: "\\u{2764}"

View File

@ -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' // should error\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: '''"

View File

@ -17,4 +17,11 @@ expectation: Fail
'\u{bbbbb}\u{aaaa}'
'😭😂😘'
'\u123'
'\u1' // should error
'\u00000000' // should error
'\u01000000' // should error
'\u9999999' // should error
'😭😂😘'