Skip to content

Commit 0cbdb8a

Browse files
authored
Merge pull request RustPython#2346 from isidentical/issue-2345
Fix crash on lexing octal escapes bigger than u8::MAX
2 parents d462f64 + d141761 commit 0cbdb8a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

parser/src/lexer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ where
457457
break;
458458
}
459459
}
460-
u8::from_str_radix(&octet_content, 8).unwrap() as char
460+
let value = u32::from_str_radix(&octet_content, 8).unwrap();
461+
char::from_u32(value).unwrap()
461462
}
462463

463464
fn parse_unicode_name(&mut self) -> Result<char, LexicalError> {
@@ -1596,7 +1597,7 @@ mod tests {
15961597

15971598
#[test]
15981599
fn test_string() {
1599-
let source = r#""double" 'single' 'can\'t' "\\\"" '\t\r\n' '\g' r'raw\'' '\200\0a'"#;
1600+
let source = r#""double" 'single' 'can\'t' "\\\"" '\t\r\n' '\g' r'raw\'' '\420' '\200\0a'"#;
16001601
let tokens = lex_source(source);
16011602
assert_eq!(
16021603
tokens,
@@ -1629,6 +1630,10 @@ mod tests {
16291630
value: String::from("raw\\'"),
16301631
is_fstring: false,
16311632
},
1633+
Tok::String {
1634+
value: String::from("Đ"),
1635+
is_fstring: false,
1636+
},
16321637
Tok::String {
16331638
value: String::from("\u{80}\u{0}a"),
16341639
is_fstring: false,

0 commit comments

Comments
 (0)