Skip to content

Commit

Permalink
fix serving custom CSS coming from --extend-css in rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Jun 21, 2024
1 parent 9185fba commit b1b4ddc
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ pub(crate) async fn rustdoc_redirector_handler(
trace!(?matched_release, "matched version");
let crate_name = matched_release.name.clone();

// we might get requests to crate-specific JS files here.
// we might get requests to crate-specific JS/CSS files here.
if let Some(ref target) = params.target {
if target.ends_with(".js") {
if target.ends_with(".js") || target.ends_with(".css") {
// this URL is actually from a crate-internal path, serve it there instead
return async {
let krate = CrateDetails::from_matched_release(&mut conn, matched_release).await?;
Expand Down Expand Up @@ -207,7 +207,7 @@ pub(crate) async fn rustdoc_redirector_handler(
}
}
}
.instrument(info_span!("serve JS for crate"))
.instrument(info_span!("serve asset for crate"))
.await;
}
}
Expand Down Expand Up @@ -2540,6 +2540,26 @@ mod test {
});
}

#[test_case("something.js")]
#[test_case("someting.css")]
fn serve_release_specific_static_assets(name: &str) {
wrapper(|env| {
env.fake_release()
.name("dummy")
.version("0.1.0")
.archive_storage(true)
.rustdoc_file_with(name, b"content")
.create()?;

let web = env.frontend();
let response = web.get(&format!("/dummy/0.1.0/{name}")).send()?;
assert!(response.status().is_success());
assert_eq!(response.text()?, "content");

Ok(())
})
}

#[test_case("search-1234.js")]
#[test_case("settings-1234.js")]
fn fallback_to_root_storage_for_some_js_assets(path: &str) {
Expand Down

0 comments on commit b1b4ddc

Please sign in to comment.