From fee7f4d4331dbdafbe985e0810a69e813f408a58 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 1 Nov 2023 12:54:49 +0000 Subject: [PATCH] fix some more error positions --- src/string_decoder.rs | 3 ++- tests/main.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/string_decoder.rs b/src/string_decoder.rs index dfb67e87..200f0c30 100644 --- a/src/string_decoder.rs +++ b/src/string_decoder.rs @@ -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), diff --git a/tests/main.rs b/tests/main.rs index 95641218..f7a032b1 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -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]