Skip to content

Commit 777b37c

Browse files
committed
Fallback in more situations without baskslash
Try to make links like this work http://127.0.0.1:3000/hyper/0.13.2/hyper/client/conn
1 parent 08526f9 commit 777b37c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/web/rustdoc.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,18 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
238238
return Ok(super::redirect(canonical));
239239
}
240240

241-
let path = {
242-
let mut path = req_path.join("/");
243-
if path.ends_with('/') {
241+
if let Some(&end) = req_path.last(){
242+
if end == "" {
244243
req_path.pop(); // get rid of empty string
245-
path.push_str("index.html");
246244
req_path.push("index.html");
245+
} else if !end.contains('.') {
246+
req_path.push("index.html");
247+
} else {
248+
// page might already have extension, so do nothing
247249
}
248-
path
249-
};
250+
}
251+
252+
let path = req_path.join("/");
250253

251254
let file = match File::from_path(&conn, &path) {
252255
Some(f) => f,
@@ -440,6 +443,7 @@ mod test {
440443
.build_result_successful(true)
441444
.rustdoc_file("settings.html", b"some data")
442445
.rustdoc_file("all.html", b"some data 2")
446+
.rustdoc_file("some_module/other_module/index.html", b"some data 2")
443447
.create()?;
444448
db.fake_release()
445449
.name("buggy").version("0.2.0")
@@ -448,8 +452,10 @@ mod test {
448452
let web = env.frontend();
449453
assert_success("/", web)?;
450454
assert_success("/crate/buggy/0.1.0/", web)?;
455+
assert_success("/crate/buggy/0.1.0/", web)?;
451456
assert_success("/buggy/0.1.0/settings.html", web)?;
452457
assert_success("/buggy/0.1.0/all.html", web)?;
458+
assert_success("/buggy/0.1.0/some_module/other_module", web)?;
453459
Ok(())
454460
});
455461
}
@@ -484,6 +490,7 @@ mod test {
484490
.rustdoc_file("dummy/index.html", b"some content")
485491
.rustdoc_file("all.html", b"html")
486492
.default_target(target).create()?;
493+
487494
let base = "/dummy/0.3.0/dummy/";
488495
assert_success(base, web)?;
489496
assert_redirect("/dummy/0.3.0/x86_64-unknown-linux-gnu/dummy/", base, web)?;

0 commit comments

Comments
 (0)