@@ -198,6 +198,7 @@ struct RustdocPage {
198198 latest_version : String ,
199199 target : String ,
200200 inner_path : String ,
201+ query : Option < String > ,
201202 is_latest_version : bool ,
202203 is_prerelease : bool ,
203204 krate : CrateDetails ,
@@ -447,7 +448,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
447448 ( target, inner_path. join ( "/" ) )
448449 } ;
449450
450- // Find the path of the latest version for the `Go to latest` and `Permalink` links
451+ // For `Permalink`, the path of the latest version, with an explicit version in it.
451452 let mut latest_path = if latest_release. build_status {
452453 let target = if target. is_empty ( ) {
453454 & krate. metadata . default_target
@@ -482,6 +483,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
482483 latest_version,
483484 target,
484485 inner_path,
486+ query : req. url . query ( ) . map ( |s| s. to_string ( ) ) ,
485487 is_latest_version,
486488 is_prerelease,
487489 metadata : krate. metadata . clone ( ) ,
@@ -523,7 +525,7 @@ fn path_for_version(file_path: &[&str], crate_details: &CrateDetails) -> String
523525 } ;
524526 // this page doesn't exist in the latest version
525527 let last_component = * file_path. last ( ) . unwrap ( ) ;
526- let search_item = if last_component == "index.html" {
528+ let search_item = if last_component == "index.html" && file_path . len ( ) >= 2 {
527529 // this is a module
528530 file_path. get ( file_path. len ( ) - 2 ) . copied ( )
529531 // no trailing slash; no one should be redirected here but we handle it gracefully anyway
@@ -840,25 +842,25 @@ mod test {
840842 let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
841843 assert_eq ! (
842844 redirect,
843- "/crate/dummy/0.2.0 /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
845+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
844846 ) ;
845847
846848 // check it keeps the subpage
847849 let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/blah/" , web) ?;
848850 assert_eq ! (
849851 redirect,
850- "/crate/dummy/0.2.0 /target-redirect/x86_64-unknown-linux-gnu/dummy/blah/index.html"
852+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/blah/index.html"
851853 ) ;
852854 let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/blah/blah.html" , web) ?;
853855 assert_eq ! (
854856 redirect,
855- "/crate/dummy/0.2.0 /target-redirect/x86_64-unknown-linux-gnu/dummy/blah/blah.html"
857+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/blah/blah.html"
856858 ) ;
857859
858860 // check it also works for deleted pages
859861 let redirect =
860862 latest_version_redirect ( "/dummy/0.1.0/dummy/struct.will-be-deleted.html" , web) ?;
861- assert_eq ! ( redirect, "/crate/dummy/0.2.0 /target-redirect/x86_64-unknown-linux-gnu/dummy/struct.will-be-deleted.html" ) ;
863+ assert_eq ! ( redirect, "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/struct.will-be-deleted.html" ) ;
862864
863865 Ok ( ( ) )
864866 } )
@@ -888,14 +890,14 @@ mod test {
888890 latest_version_redirect ( "/dummy/0.1.0/x86_64-pc-windows-msvc/dummy" , web) ?;
889891 assert_eq ! (
890892 redirect,
891- "/crate/dummy/0.2.0 /target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
893+ "/crate/dummy/latest /target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
892894 ) ;
893895
894896 let redirect =
895897 latest_version_redirect ( "/dummy/0.1.0/x86_64-pc-windows-msvc/dummy/" , web) ?;
896898 assert_eq ! (
897899 redirect,
898- "/crate/dummy/0.2.0 /target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
900+ "/crate/dummy/latest /target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
899901 ) ;
900902
901903 let redirect = latest_version_redirect (
@@ -904,7 +906,7 @@ mod test {
904906 ) ?;
905907 assert_eq ! (
906908 redirect,
907- "/crate/dummy/0.2.0 /target-redirect/x86_64-pc-windows-msvc/dummy/struct.Blah.html"
909+ "/crate/dummy/latest /target-redirect/x86_64-pc-windows-msvc/dummy/struct.Blah.html"
908910 ) ;
909911
910912 Ok ( ( ) )
@@ -930,7 +932,7 @@ mod test {
930932
931933 let web = env. frontend ( ) ;
932934 let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
933- assert_eq ! ( redirect, "/crate/dummy/0.2.0 " ) ;
935+ assert_eq ! ( redirect, "/crate/dummy/latest " ) ;
934936
935937 Ok ( ( ) )
936938 } )
@@ -964,13 +966,13 @@ mod test {
964966 let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
965967 assert_eq ! (
966968 redirect,
967- "/crate/dummy/0.2.0 /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
969+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
968970 ) ;
969971
970972 let redirect = latest_version_redirect ( "/dummy/0.2.1/dummy/" , web) ?;
971973 assert_eq ! (
972974 redirect,
973- "/crate/dummy/0.2.0 /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
975+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
974976 ) ;
975977
976978 Ok ( ( ) )
@@ -1007,13 +1009,13 @@ mod test {
10071009 let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
10081010 assert_eq ! (
10091011 redirect,
1010- "/crate/dummy/0.2.1 /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
1012+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
10111013 ) ;
10121014
10131015 let redirect = latest_version_redirect ( "/dummy/0.2.0/dummy/" , web) ?;
10141016 assert_eq ! (
10151017 redirect,
1016- "/crate/dummy/0.2.1 /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
1018+ "/crate/dummy/latest /target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
10171019 ) ;
10181020
10191021 Ok ( ( ) )
@@ -1807,7 +1809,7 @@ mod test {
18071809 "/tungstenite/0.10.0/tungstenite/?search=String%20-%3E%20Message" ,
18081810 env. frontend( )
18091811 ) ?,
1810- "/crate/tungstenite/0.11.0 /target-redirect/x86_64-unknown-linux-gnu/tungstenite/index.html?search=String%20-%3E%20Message" ,
1812+ "/crate/tungstenite/latest /target-redirect/x86_64-unknown-linux-gnu/tungstenite/index.html?search=String%20-%3E%20Message" ,
18111813 ) ;
18121814 Ok ( ( ) )
18131815 } ) ;
@@ -1824,7 +1826,7 @@ mod test {
18241826 . source_file ( "src/objects/exc.rs" , b"//! some docs" )
18251827 . create ( ) ?;
18261828 env. fake_release ( ) . name ( "pyo3" ) . version ( "0.13.2" ) . create ( ) ?;
1827- let target_redirect = "/crate/pyo3/0.13.2 /target-redirect/x86_64-unknown-linux-gnu/src/pyo3/objects/exc.rs.html" ;
1829+ let target_redirect = "/crate/pyo3/latest /target-redirect/x86_64-unknown-linux-gnu/src/pyo3/objects/exc.rs.html" ;
18281830 assert_eq ! (
18291831 latest_version_redirect(
18301832 "/pyo3/0.2.7/src/pyo3/objects/exc.rs.html" ,
@@ -1834,7 +1836,7 @@ mod test {
18341836 ) ;
18351837 assert_redirect (
18361838 target_redirect,
1837- "/pyo3/0.13.2 /pyo3/?search=exc" ,
1839+ "/pyo3/latest /pyo3/?search=exc" ,
18381840 env. frontend ( ) ,
18391841 ) ?;
18401842 Ok ( ( ) )
0 commit comments