Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions crates/bin/docs_rs_web/src/handlers/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@ pub(crate) async fn json_download_handler(

stripped_format_version
.parse::<RustdocJsonFormatVersion>()
.context("can't parse format version")?
.context("can't parse format version")
.map_err(AxumNope::BadRequest)?
} else {
RustdocJsonFormatVersion::Latest
};
Expand Down Expand Up @@ -1074,7 +1075,10 @@ mod test {
RUSTDOC_JSON_COMPRESSION_ALGORITHMS, read_format_version_from_rustdoc_json,
};
use docs_rs_storage::{decompress, testing::check_archive_consistency};
use docs_rs_types::Version;
use docs_rs_types::{
Version,
testing::{KRATE, V2},
};
use docs_rs_uri::encode_url_path;
use kuchikiki::traits::TendrilSink;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -3639,6 +3643,34 @@ mod test {
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn json_download_bad_request() -> Result<()> {
let env = TestEnvironment::new().await?;

env.fake_release()
.await
.name(KRATE)
.version(V2)
.archive_storage(true)
.default_target("x86_64-unknown-linux-gnu")
.create()
.await?;

let web = env.web_app().await;

let response = web
.get(&format!("/crate/{KRATE}/{V2}/json/963570%40"))
.await?;
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert!(
response
.text()
.await?
.contains("can&#39;t parse format version")
);
Ok(())
}

#[test_case("0.1.0/json"; "rustdoc status false")]
#[test_case("0.2.0/unknown-target/json"; "unknown target")]
#[test_case("0.2.0/json/99"; "target file doesnt exist")]
Expand Down
Loading