Skip to content

Commit

Permalink
fix some more error positions
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 1, 2023
1 parent 28d2812 commit fee7f4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/string_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ fn parse_escape(data: &[u8], index: usize) -> JsonResult<(char, usize)> {
None => json_err!(EofWhileParsingString, index),
}
}
Some(_) => json_err!(UnexpectedEndOfHexEscape, index),
Some(slice) if slice.starts_with(b"\\") => json_err!(UnexpectedEndOfHexEscape, index + 2),
Some(_) => json_err!(UnexpectedEndOfHexEscape, index + 1),
None => match data.get(index + 1) {
Some(b'\\') | None => json_err!(EofWhileParsingString, data.len()),
Some(_) => json_err!(UnexpectedEndOfHexEscape, index + 1),
Expand Down
5 changes: 3 additions & 2 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ string_test_errors! {
u4_unclosed2: r#""\udBdd"# => "EofWhileParsingString @ 7 - 1:7";
line_leading_surrogate: r#""\uddBd""# => "LoneLeadingSurrogateInHexEscape @ 6 - 1:7";
unexpected_hex_escape1: r#""\udBd8x"# => "UnexpectedEndOfHexEscape @ 7 - 1:8";
unexpected_hex_escape2: r#""\udBd8xx"# => "UnexpectedEndOfHexEscape @ 6 - 1:7";
unexpected_hex_escape2: r#""\udBd8xx"# => "UnexpectedEndOfHexEscape @ 7 - 1:8";
unexpected_hex_escape3: "\"un\\uDBBB\0" => "UnexpectedEndOfHexEscape @ 9 - 1:10";
unexpected_hex_escape4: r#""\ud8e0\e"# => "UnexpectedEndOfHexEscape @ 8 - 1:9";
newline_in_string: "\"\n" => "ControlCharacterWhileParsingString @ 1 - 2:0";
unexpected_end_of_hex: "\"un\\uDBBB\0" => "UnexpectedEndOfHexEscape @ 9 - 1:10";
}

#[test]
Expand Down

0 comments on commit fee7f4d

Please sign in to comment.