json
json copied to clipboard
Wrong positions for `InvalidUnicodeCodePoint` caused by `from_utf8`
Given the following example:
fn main() {
let json_vec = vec![34, 92, 34, 206, 44, 163, 34];
let error = serde_json::from_slice::<serde_json::Value>(&json_vec).unwrap_err();
dbg!(error.to_string());
}
Serde JSON gives the error "invalid unicode code point at line 1 column 7", but I would argue that the error is at column 4, not 7.
I think this is caused by one of the *from_utf8 calls, e.g. this:
let raw = match String::from_utf8(raw) {
Ok(raw) => raw,
Err(_) => return error(self, ErrorCode::InvalidUnicodeCodePoint),
};
Instead of using the position of the end of of the string, Serde JSON should use start + e.valid_up_to() + 1, similar to this code.