Skip to content

Commit b7010d7

Browse files
jyn514syphar
authored andcommitted
Fix crash when clicking "go to latest" on non-rust file that was deleted
1 parent f6e58b3 commit b7010d7

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/web/rustdoc.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,9 @@ fn path_for_version(
521521
// this is an item
522522
last_component.split('.').nth(1)
523523
} else {
524-
// this is a source file; try searching for the module
525-
Some(last_component.strip_suffix(".rs.html").unwrap())
524+
// if this is a Rust source file, try searching for the module;
525+
// else, don't try searching at all, we don't know how to find it
526+
last_component.strip_suffix(".rs.html")
526527
};
527528
if let Some(search) = search_item {
528529
format!("{}?search={}", platform, search)
@@ -1810,4 +1811,29 @@ mod test {
18101811
Ok(())
18111812
})
18121813
}
1814+
1815+
#[test]
1816+
fn test_redirect_source_not_rust() {
1817+
wrapper(|env| {
1818+
env.fake_release()
1819+
.name("winapi")
1820+
.version("0.3.8")
1821+
.source_file("src/docs.md", b"created by Peter Rabbit")
1822+
.create()?;
1823+
1824+
env.fake_release()
1825+
.name("winapi")
1826+
.version("0.3.9")
1827+
.create()?;
1828+
1829+
assert_success("/winapi/0.3.8/src/winapi/docs.md.html", env.frontend())?;
1830+
// people can end up here from clicking "go to latest" while in source view
1831+
assert_redirect(
1832+
"/crate/winapi/0.3.9/target-redirect/src/winapi/docs.md.html",
1833+
"/winapi/0.3.9/winapi/",
1834+
env.frontend(),
1835+
)?;
1836+
Ok(())
1837+
})
1838+
}
18131839
}

0 commit comments

Comments
 (0)