Skip to content

Commit 2f812d0

Browse files
committed
Add test of RawValue deserialization from invalid utf-8
1 parent 9bcb08f commit 2f812d0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,25 @@ fn test_boxed_raw_value() {
22012201
assert_eq!(r#"["a",42,{"foo": "bar"},null]"#, array_to_string);
22022202
}
22032203

2204+
#[cfg(feature = "raw_value")]
2205+
#[test]
2206+
fn test_raw_invalid_utf8() {
2207+
use serde_json::value::RawValue;
2208+
2209+
let j = &[b'"', b'\xCE', b'\xF8', b'"'];
2210+
let value_err = serde_json::from_slice::<Value>(j).unwrap_err();
2211+
let raw_value_err = serde_json::from_slice::<Box<RawValue>>(j).unwrap_err();
2212+
2213+
assert_eq!(
2214+
value_err.to_string(),
2215+
"invalid unicode code point at line 1 column 4",
2216+
);
2217+
assert_eq!(
2218+
raw_value_err.to_string(),
2219+
"invalid unicode code point at line 1 column 4",
2220+
);
2221+
}
2222+
22042223
#[test]
22052224
fn test_borrow_in_map_key() {
22062225
#[derive(Deserialize, Debug)]

0 commit comments

Comments
 (0)