Skip to content

Don't serve non-rustdoc resources from the shared resource handler #1158

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
Closed
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
4 changes: 4 additions & 0 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ pub struct SharedResourceHandler;
impl Handler for SharedResourceHandler {
fn handle(&self, req: &mut Request) -> IronResult<Response> {
let path = req.url.path();
if path.len() > 1 {
// All rustdoc shared resources are hosted at the root
return Err(Nope::ResourceNotFound.into());
}
let filename = path.last().unwrap(); // unwrap is fine: vector is non-empty
let suffix = filename.split('.').last().unwrap(); // unwrap is fine: split always works
if ["js", "css", "woff", "svg"].contains(&suffix) {
Expand Down