Skip to content

Add hack so that docs from 2018-11-29 are styled correctly #1331

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub(super) fn build_routes() -> Routes {
);
routes.rustdoc_page(
"/:crate/:version/:target",
super::rustdoc::rustdoc_redirector_handler,
super::rustdoc::rustdoc_static_file_hack,
);
routes.rustdoc_page(
"/:crate/:version/:target/",
Expand Down
25 changes: 25 additions & 0 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ impl iron::Handler for RustLangRedirector {
}
}

pub(super) fn rustdoc_static_file_hack(req: &mut Request) -> IronResult<Response> {
// HACK(#1327): If the crate incorrectly used a relative link to `/:crate/:version/static-resource.css`,
// then this will return a redirect instead of a 404, so the `shared_files_handler` won't serve the right file.
// Try to avoid this by only serving a redirect for valid targets.
let router = extension!(req, Router);
let target = router.find("target").unwrap();
if target.contains(|c: char| !(c.is_ascii_alphanumeric() || c == '_' || c == '-')) {
Err(Nope::ResourceNotFound.into())
} else {
rustdoc_redirector_handler(req)
}
}

/// Handler called for `/:crate` and `/:crate/:version` URLs. Automatically redirects to the docs
/// or crate details page based on whether the given crate version was successfully built.
pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
Expand Down Expand Up @@ -1736,4 +1749,16 @@ mod test {
Ok(())
})
}

#[test]
fn static_file_hack() {
wrapper(|env| {
let static_file = "/hexponent/0.3.1/rustdoc-20181129-1.32.0-nightly-3e90a12a8.css";
let response = env.frontend().get(static_file).send()?;
// make sure there's no redirect
assert_eq!(response.url().path(), static_file);
assert_eq!(response.status(), StatusCode::NOT_FOUND);
Ok(())
})
}
}