Skip to content

Commit

Permalink
Use Path's logic for file extensions instead of rewriting it
Browse files Browse the repository at this point in the history
This avoids bugs when files are named `svg`, without an extension.
  • Loading branch information
jyn514 committed Mar 23, 2021
1 parent ce3f1b8 commit 2f3e356
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use iron::{
use lol_html::errors::RewritingError;
use router::Router;
use serde::Serialize;
use std::path::Path;

#[derive(Clone)]
pub struct RustLangRedirector {
Expand Down Expand Up @@ -644,13 +645,14 @@ impl Handler for SharedResourceHandler {
fn handle(&self, req: &mut Request) -> IronResult<Response> {
let path = req.url.path();
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) {
let storage = extension!(req, Storage);
let config = extension!(req, Config);
if let Some(extension) = Path::new(filename).extension() {
if ["js", "css", "woff", "svg"].iter().any(|s| *s == extension) {
let storage = extension!(req, Storage);
let config = extension!(req, Config);

if let Ok(file) = File::from_path(&storage, filename, &config) {
return Ok(file.serve());
if let Ok(file) = File::from_path(&storage, filename, &config) {
return Ok(file.serve());
}
}
}

Expand Down

0 comments on commit 2f3e356

Please sign in to comment.