Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix serving custom CSS coming from --extend-css in rustdoc #2525

Merged
merged 1 commit into from
Jun 21, 2024
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
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
Loading