| 
1 | 1 | use std::ops::Range;  | 
2 | 2 | use std::str::{from_utf8, from_utf8_unchecked};  | 
3 | 3 | 
 
  | 
4 |  | -use crate::errors::{json_err, json_error, JsonResult};  | 
 | 4 | +use crate::errors::{json_err, json_error, JsonErrorType, JsonResult};  | 
5 | 5 | 
 
  | 
6 | 6 | pub type Tape = Vec<u8>;  | 
7 | 7 | 
 
  | 
@@ -154,16 +154,28 @@ fn decode_to_tape<'t, 'j>(  | 
154 | 154 |                 b'n' => tape.push(b'\n'),  | 
155 | 155 |                 b'r' => tape.push(b'\r'),  | 
156 | 156 |                 b't' => tape.push(b'\t'),  | 
157 |  | -                b'u' => {  | 
158 |  | -                    let (c, new_index) = parse_escape(data, index)?;  | 
159 |  | -                    ascii_only = false;  | 
160 |  | -                    index = new_index;  | 
161 |  | -                    tape.extend_from_slice(c.encode_utf8(&mut [0_u8; 4]).as_bytes());  | 
162 |  | -                }  | 
 | 157 | +                b'u' => match parse_escape(data, index) {  | 
 | 158 | +                    Ok((c, new_index)) => {  | 
 | 159 | +                        ascii_only = false;  | 
 | 160 | +                        index = new_index;  | 
 | 161 | +                        tape.extend_from_slice(c.encode_utf8(&mut [0_u8; 4]).as_bytes());  | 
 | 162 | +                    }  | 
 | 163 | +                    Err(e) => {  | 
 | 164 | +                        if allow_partial && e.error_type == JsonErrorType::EofWhileParsingString {  | 
 | 165 | +                            let s = to_str(tape, ascii_only, start)?;  | 
 | 166 | +                            return Ok((unsafe { StringOutput::tape(s, ascii_only) }, e.index));  | 
 | 167 | +                        }  | 
 | 168 | +                        return Err(e);  | 
 | 169 | +                    }  | 
 | 170 | +                },  | 
163 | 171 |                 _ => return json_err!(InvalidEscape, index),  | 
164 | 172 |             }  | 
165 | 173 |             index += 1;  | 
166 | 174 |         } else {  | 
 | 175 | +            if allow_partial {  | 
 | 176 | +                let s = to_str(tape, ascii_only, start)?;  | 
 | 177 | +                return Ok((unsafe { StringOutput::tape(s, ascii_only) }, index));  | 
 | 178 | +            }  | 
167 | 179 |             return json_err!(EofWhileParsingString, index);  | 
168 | 180 |         }  | 
169 | 181 | 
 
  | 
 | 
0 commit comments