@@ -495,42 +495,40 @@ impl<'a, 'de, 's> de::Deserializer<'de> for &'a mut Deserializer<'de, 's> {
495
495
{
496
496
let escaped_string = self . parse_str ( ) ?;
497
497
498
- if let Some ( string_unescape_buffer) = self . string_unescape_buffer . as_deref_mut ( ) {
499
- if escaped_string. as_bytes ( ) . contains ( & b'\\' ) {
500
- let mut string_unescape_buffer_write_position = 0 ;
498
+ // If the unescape buffer is not provided, skip unescaping strings
499
+ let Some ( string_unescape_buffer) = self . string_unescape_buffer . as_deref_mut ( ) else {
500
+ return visitor. visit_borrowed_str ( escaped_string) ;
501
+ } ;
501
502
502
- for fragment in crate :: str:: EscapedStr ( escaped_string) . fragments ( ) {
503
- let char_encode_buffer = & mut [ 0 ; 4 ] ;
503
+ // If the escaped string doesn't contain '\\', it' can't have any escaped characters
504
+ if !escaped_string. as_bytes ( ) . contains ( & b'\\' ) {
505
+ return visitor. visit_borrowed_str ( escaped_string) ;
506
+ }
504
507
505
- let unescaped_bytes = match fragment? {
506
- crate :: str:: EscapedStringFragment :: NotEscaped ( fragment) => {
507
- fragment. as_bytes ( )
508
- }
509
- crate :: str:: EscapedStringFragment :: Escaped ( c) => {
510
- c. encode_utf8 ( char_encode_buffer) . as_bytes ( )
511
- }
512
- } ;
508
+ let mut string_unescape_buffer_write_position = 0 ;
513
509
514
- string_unescape_buffer[ string_unescape_buffer_write_position..]
515
- . get_mut ( ..unescaped_bytes. len ( ) )
516
- . ok_or ( Error :: EscapedStringIsTooLong ) ?
517
- . copy_from_slice ( unescaped_bytes) ;
510
+ for fragment in crate :: str:: EscapedStr ( escaped_string) . fragments ( ) {
511
+ let char_encode_buffer = & mut [ 0 ; 4 ] ;
518
512
519
- string_unescape_buffer_write_position += unescaped_bytes. len ( ) ;
513
+ let unescaped_bytes = match fragment? {
514
+ crate :: str:: EscapedStringFragment :: NotEscaped ( fragment) => fragment. as_bytes ( ) ,
515
+ crate :: str:: EscapedStringFragment :: Escaped ( c) => {
516
+ c. encode_utf8 ( char_encode_buffer) . as_bytes ( )
520
517
}
518
+ } ;
521
519
522
- visitor. visit_str (
523
- str:: from_utf8 (
524
- & string_unescape_buffer[ ..string_unescape_buffer_write_position] ,
525
- )
526
- . map_err ( |_| Error :: InvalidUnicodeCodePoint ) ?,
527
- )
528
- } else {
529
- visitor. visit_borrowed_str ( escaped_string)
530
- }
531
- } else {
532
- visitor. visit_borrowed_str ( escaped_string)
520
+ string_unescape_buffer[ string_unescape_buffer_write_position..]
521
+ . get_mut ( ..unescaped_bytes. len ( ) )
522
+ . ok_or ( Error :: EscapedStringIsTooLong ) ?
523
+ . copy_from_slice ( unescaped_bytes) ;
524
+
525
+ string_unescape_buffer_write_position += unescaped_bytes. len ( ) ;
533
526
}
527
+
528
+ visitor. visit_str (
529
+ str:: from_utf8 ( & string_unescape_buffer[ ..string_unescape_buffer_write_position] )
530
+ . map_err ( |_| Error :: InvalidUnicodeCodePoint ) ?,
531
+ )
534
532
}
535
533
536
534
/// Unsupported. String is not available in no-std.
0 commit comments