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

Error position wrong for "unicode code point" error #1110

Open
samuelcolvin opened this issue Feb 4, 2024 · 1 comment
Open

Error position wrong for "unicode code point" error #1110

samuelcolvin opened this issue Feb 4, 2024 · 1 comment

Comments

@samuelcolvin
Copy link

The following

fn main() {
    let json = vec![b'"', 128, b' ', b' ', b' ', b'"'];
    let e = serde_json::from_slice::<String>(&json).unwrap_err();
    println!("serde_json error: {e}");
    let e = std::str::from_utf8(&json).unwrap_err();
    println!("from_utf error:   {e}");
}

outputs:

serde_json error: invalid unicode code point at line 1 column 6
from_utf error:   invalid utf-8 sequence of 1 bytes from index 1

serde_json claims the error position was a the end of the JSON string, not where it actually was. If you insert more spaces, the error always comes at the next ".

In comparison, if the error is caused by a control character, the position is correct:

fn main() {
    // let json = vec![b'"', 128, b' ', b' ', b' ', b'"'];
    let json = vec![b'"', b'\t', b' ', b' ', b' ', b'"'];
    let e = serde_json::from_slice::<String>(&json).unwrap_err();
    println!("serde_json error: {e}");
}

outputs:

serde_json error: control character (\u0000-\u001F) found while parsing a string at line 1 column 2

I'm using serde_json version 1.0.87.

@samuelcolvin
Copy link
Author

Bump. Anyone?

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