@@ -198,6 +198,7 @@ struct RustdocPage {
198
198
latest_version : String ,
199
199
target : String ,
200
200
inner_path : String ,
201
+ query : Option < String > ,
201
202
is_latest_version : bool ,
202
203
is_prerelease : bool ,
203
204
krate : CrateDetails ,
@@ -447,7 +448,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
447
448
( target, inner_path. join ( "/" ) )
448
449
} ;
449
450
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.
451
452
let mut latest_path = if latest_release. build_status {
452
453
let target = if target. is_empty ( ) {
453
454
& krate. metadata . default_target
@@ -482,6 +483,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
482
483
latest_version,
483
484
target,
484
485
inner_path,
486
+ query : req. url . query ( ) . map ( |s| s. to_string ( ) ) ,
485
487
is_latest_version,
486
488
is_prerelease,
487
489
metadata : krate. metadata . clone ( ) ,
@@ -523,7 +525,7 @@ fn path_for_version(file_path: &[&str], crate_details: &CrateDetails) -> String
523
525
} ;
524
526
// this page doesn't exist in the latest version
525
527
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 {
527
529
// this is a module
528
530
file_path. get ( file_path. len ( ) - 2 ) . copied ( )
529
531
// no trailing slash; no one should be redirected here but we handle it gracefully anyway
@@ -840,25 +842,25 @@ mod test {
840
842
let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
841
843
assert_eq ! (
842
844
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"
844
846
) ;
845
847
846
848
// check it keeps the subpage
847
849
let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/blah/" , web) ?;
848
850
assert_eq ! (
849
851
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"
851
853
) ;
852
854
let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/blah/blah.html" , web) ?;
853
855
assert_eq ! (
854
856
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"
856
858
) ;
857
859
858
860
// check it also works for deleted pages
859
861
let redirect =
860
862
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" ) ;
862
864
863
865
Ok ( ( ) )
864
866
} )
@@ -888,14 +890,14 @@ mod test {
888
890
latest_version_redirect ( "/dummy/0.1.0/x86_64-pc-windows-msvc/dummy" , web) ?;
889
891
assert_eq ! (
890
892
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"
892
894
) ;
893
895
894
896
let redirect =
895
897
latest_version_redirect ( "/dummy/0.1.0/x86_64-pc-windows-msvc/dummy/" , web) ?;
896
898
assert_eq ! (
897
899
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"
899
901
) ;
900
902
901
903
let redirect = latest_version_redirect (
@@ -904,7 +906,7 @@ mod test {
904
906
) ?;
905
907
assert_eq ! (
906
908
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"
908
910
) ;
909
911
910
912
Ok ( ( ) )
@@ -930,7 +932,7 @@ mod test {
930
932
931
933
let web = env. frontend ( ) ;
932
934
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 " ) ;
934
936
935
937
Ok ( ( ) )
936
938
} )
@@ -964,13 +966,13 @@ mod test {
964
966
let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
965
967
assert_eq ! (
966
968
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"
968
970
) ;
969
971
970
972
let redirect = latest_version_redirect ( "/dummy/0.2.1/dummy/" , web) ?;
971
973
assert_eq ! (
972
974
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"
974
976
) ;
975
977
976
978
Ok ( ( ) )
@@ -1007,13 +1009,13 @@ mod test {
1007
1009
let redirect = latest_version_redirect ( "/dummy/0.1.0/dummy/" , web) ?;
1008
1010
assert_eq ! (
1009
1011
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"
1011
1013
) ;
1012
1014
1013
1015
let redirect = latest_version_redirect ( "/dummy/0.2.0/dummy/" , web) ?;
1014
1016
assert_eq ! (
1015
1017
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"
1017
1019
) ;
1018
1020
1019
1021
Ok ( ( ) )
@@ -1807,7 +1809,7 @@ mod test {
1807
1809
"/tungstenite/0.10.0/tungstenite/?search=String%20-%3E%20Message" ,
1808
1810
env. frontend( )
1809
1811
) ?,
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" ,
1811
1813
) ;
1812
1814
Ok ( ( ) )
1813
1815
} ) ;
@@ -1824,7 +1826,7 @@ mod test {
1824
1826
. source_file ( "src/objects/exc.rs" , b"//! some docs" )
1825
1827
. create ( ) ?;
1826
1828
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" ;
1828
1830
assert_eq ! (
1829
1831
latest_version_redirect(
1830
1832
"/pyo3/0.2.7/src/pyo3/objects/exc.rs.html" ,
@@ -1834,7 +1836,7 @@ mod test {
1834
1836
) ;
1835
1837
assert_redirect (
1836
1838
target_redirect,
1837
- "/pyo3/0.13.2 /pyo3/?search=exc" ,
1839
+ "/pyo3/latest /pyo3/?search=exc" ,
1838
1840
env. frontend ( ) ,
1839
1841
) ?;
1840
1842
Ok ( ( ) )
0 commit comments