@@ -462,6 +462,19 @@ where
462462 }
463463 }
464464
465+ fn parse_octet ( & mut self , first : char ) -> char {
466+ let mut octet_content = String :: new ( ) ;
467+ octet_content. push ( first) ;
468+ while octet_content. len ( ) < 3 {
469+ if let Some ( '0' ..='7' ) = self . chr0 {
470+ octet_content. push ( self . next_char ( ) . unwrap ( ) )
471+ } else {
472+ break ;
473+ }
474+ }
475+ u8:: from_str_radix ( & octet_content, 8 ) . unwrap ( ) as char
476+ }
477+
465478 fn lex_string (
466479 & mut self ,
467480 is_bytes : bool ,
@@ -523,6 +536,9 @@ where
523536 Some ( 'U' ) => string_content. push ( self . unicode_literal ( 8 ) ?) ,
524537 Some ( 'x' ) if !is_bytes => string_content. push ( self . unicode_literal ( 2 ) ?) ,
525538 Some ( 'v' ) => string_content. push ( '\x0b' ) ,
539+ Some ( o @ '0' ..='7' ) if !is_bytes => {
540+ string_content. push ( self . parse_octet ( o) )
541+ }
526542 Some ( c) => {
527543 string_content. push ( '\\' ) ;
528544 string_content. push ( c) ;
@@ -1642,7 +1658,7 @@ mod tests {
16421658
16431659 #[ test]
16441660 fn test_string ( ) {
1645- let source = r#""double" 'single' 'can\'t' "\\\"" '\t\r\n' '\g' r'raw\''"# ;
1661+ let source = r#""double" 'single' 'can\'t' "\\\"" '\t\r\n' '\g' r'raw\'' '\200\0a' "# ;
16461662 let tokens = lex_source ( source) ;
16471663 assert_eq ! (
16481664 tokens,
@@ -1675,6 +1691,10 @@ mod tests {
16751691 value: String :: from( "raw\' " ) ,
16761692 is_fstring: false ,
16771693 } ,
1694+ Tok :: String {
1695+ value: String :: from( "\u{80} \u{0} a" ) ,
1696+ is_fstring: false ,
1697+ } ,
16781698 Tok :: Newline ,
16791699 ]
16801700 ) ;
0 commit comments