diff --git a/rust/strawcore/src/net.rs b/rust/strawcore/src/net.rs index b95a13424..18ae2c6d9 100644 --- a/rust/strawcore/src/net.rs +++ b/rust/strawcore/src/net.rs @@ -80,9 +80,14 @@ pub(crate) async fn read_capped_body(resp: reqwest::Response, cap: usize) -> Opt } buf.extend_from_slice(&chunk); } - // Lossy decode: a strict from_utf8 would drop the whole response on a - // single mojibake byte; serde_json tolerates U+FFFD in string values. - Some(String::from_utf8_lossy(&buf).into_owned()) + // Prefer a zero-copy move on valid UTF-8 (the common case); fall back to a + // lossy copy only on a mojibake byte (a strict from_utf8 would otherwise + // drop the whole response — serde_json tolerates U+FFFD in string values). + // Mirrors the core downloader's default_impl fast path (S4). + Some(match String::from_utf8(buf) { + Ok(s) => s, + Err(e) => String::from_utf8_lossy(e.as_bytes()).into_owned(), + }) } // ---------------------------------------------------------------------------