fix: added a dedicated test to confirm that serde_json correctly handles JSON strings with leading and trailing whitespace (#15789)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Tomás Andróil
2025-04-19 10:32:46 +02:00
committed by GitHub
parent 87d12ed789
commit 15dfb13a2b
3 changed files with 16 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -8250,6 +8250,7 @@ dependencies = [
"pin-project",
"rand 0.9.0",
"reth-tracing",
"serde",
"serde_json",
"thiserror 2.0.12",
"tokio",

View File

@@ -32,5 +32,6 @@ interprocess = { workspace = true, features = ["tokio"] }
[dev-dependencies]
tokio-stream = { workspace = true, features = ["sync"] }
serde.workspace = true
reth-tracing.workspace = true
rand.workspace = true

View File

@@ -300,4 +300,18 @@ mod tests {
assert_eq!(request, "{ test: 1 }");
assert_eq!(request2, "{ test: 2 }");
}
#[test]
fn serde_json_accepts_whitespace_wrapped_json() {
let json = " { \"key\": \"value\" } ";
#[derive(serde::Deserialize, Debug, PartialEq)]
struct Obj {
key: String,
}
let parsed: Result<Obj, _> = serde_json::from_str(json);
assert!(parsed.is_ok(), "serde_json should accept whitespace-wrapped JSON");
assert_eq!(parsed.unwrap(), Obj { key: "value".into() });
}
}