File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -363,6 +363,14 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
363
363
364
364
return if ctry ! ( req, storage. exists( & path) ) {
365
365
redirect ( & name, & version, & req_path[ 3 ..] )
366
+ } else if req_path. get ( 3 ) . map_or ( false , |p| p. contains ( '-' ) ) {
367
+ // This is a target, not a module; it may not have been built.
368
+ // Redirect to the default target and show a search page instead of a hard 404.
369
+ redirect (
370
+ & format ! ( "/crate/{}" , name) ,
371
+ & format ! ( "{}/target-redirect" , version) ,
372
+ & req_path[ 3 ..] ,
373
+ )
366
374
} else {
367
375
Err ( Nope :: ResourceNotFound . into ( ) )
368
376
} ;
@@ -1746,4 +1754,24 @@ mod test {
1746
1754
Ok ( ( ) )
1747
1755
} )
1748
1756
}
1757
+
1758
+ #[ test]
1759
+ fn test_missing_target_redirects_to_search ( ) {
1760
+ wrapper ( |env| {
1761
+ env. fake_release ( )
1762
+ . name ( "winapi" )
1763
+ . version ( "0.3.9" )
1764
+ . rustdoc_file ( "winapi/macro.ENUM.html" )
1765
+ . create ( ) ?;
1766
+
1767
+ assert_redirect (
1768
+ "/winapi/0.3.9/x86_64-unknown-linux-gnu/winapi/macro.ENUM.html" ,
1769
+ "/winapi/0.3.9/winapi/macro.ENUM.html" ,
1770
+ env. frontend ( ) ,
1771
+ ) ?;
1772
+ assert_not_found ( "/winapi/0.3.9/winapi/struct.not_here.html" , env. frontend ( ) ) ?;
1773
+
1774
+ Ok ( ( ) )
1775
+ } )
1776
+ }
1749
1777
}
You can’t perform that action at this time.
0 commit comments