Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong positions for InvalidUnicodeCodePoint caused by from_utf8 #1083

Open
samuelcolvin opened this issue Nov 2, 2023 · 0 comments
Open

Comments

@samuelcolvin
Copy link

samuelcolvin commented Nov 2, 2023

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.

@samuelcolvin samuelcolvin changed the title Wrong positions for InvalidUnicodeCodePoint caused by str::from_utf8 Wrong positions for InvalidUnicodeCodePoint caused by from_utf8 Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant