Skip to content

Commit

Permalink
Add test of RawValue deserialization from invalid utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 28, 2021
1 parent 9bcb08f commit 2f812d0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,25 @@ fn test_boxed_raw_value() {
assert_eq!(r#"["a",42,{"foo": "bar"},null]"#, array_to_string);
}

#[cfg(feature = "raw_value")]
#[test]
fn test_raw_invalid_utf8() {
use serde_json::value::RawValue;

let j = &[b'"', b'\xCE', b'\xF8', b'"'];
let value_err = serde_json::from_slice::<Value>(j).unwrap_err();
let raw_value_err = serde_json::from_slice::<Box<RawValue>>(j).unwrap_err();

assert_eq!(
value_err.to_string(),
"invalid unicode code point at line 1 column 4",
);
assert_eq!(
raw_value_err.to_string(),
"invalid unicode code point at line 1 column 4",
);
}

#[test]
fn test_borrow_in_map_key() {
#[derive(Deserialize, Debug)]
Expand Down

0 comments on commit 2f812d0

Please sign in to comment.