File tree Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -584,11 +584,25 @@ pub fn search_handler(req: &mut Request) -> IronResult<Response> {
584
584
return redirect_to_random_crate ( req, & mut conn) ;
585
585
}
586
586
587
- let ( krate, query) = match query. split_once ( "::" ) {
587
+ let ( krate, mut query) = match query. split_once ( "::" ) {
588
588
Some ( ( krate, query) ) => ( krate. to_string ( ) , format ! ( "?search={query}" ) ) ,
589
589
None => ( query. clone ( ) , "" . to_string ( ) ) ,
590
590
} ;
591
591
592
+ for ( k, v) in params
593
+ . iter ( )
594
+ . filter ( |( k, _) | !matches ! ( k. as_ref( ) , "i-am-feeling-lucky" | "query" ) )
595
+ {
596
+ if query. is_empty ( ) {
597
+ query. push ( '?' ) ;
598
+ } else {
599
+ query. push ( '&' )
600
+ }
601
+ query. push_str ( k) ;
602
+ query. push ( '=' ) ;
603
+ query. push_str ( v) ;
604
+ }
605
+
592
606
// since we never pass a version into `match_version` here, we'll never get
593
607
// `MatchVersion::Exact`, so the distinction between `Exact` and `Semver` doesn't
594
608
// matter
@@ -907,6 +921,21 @@ mod tests {
907
921
} )
908
922
}
909
923
924
+ #[ test]
925
+ fn search_coloncolon_path_redirects_to_crate_docs_and_keeps_query ( ) {
926
+ wrapper ( |env| {
927
+ let web = env. frontend ( ) ;
928
+ env. fake_release ( ) . name ( "some_random_crate" ) . create ( ) ?;
929
+
930
+ assert_redirect (
931
+ "/releases/search?query=some_random_crate::somepath&go_to_first=true" ,
932
+ "/some_random_crate/1.0.0/some_random_crate/?search=somepath&go_to_first=true" ,
933
+ web,
934
+ ) ?;
935
+ Ok ( ( ) )
936
+ } )
937
+ }
938
+
910
939
#[ test]
911
940
fn search_result_passes_cratesio_pagination_links ( ) {
912
941
wrapper ( |env| {
Original file line number Diff line number Diff line change @@ -46,12 +46,19 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
46
46
permanent : bool ,
47
47
path_in_crate : Option < & str > ,
48
48
) -> IronResult < Response > {
49
- if let Some ( query) = req. url . query ( ) {
50
- url_str. push ( '?' ) ;
51
- url_str. push_str ( query) ;
52
- } else if let Some ( path) = path_in_crate {
49
+ let mut question_mark = false ;
50
+ if let Some ( path) = path_in_crate {
53
51
url_str. push_str ( "?search=" ) ;
54
52
url_str. push_str ( path) ;
53
+ question_mark = true ;
54
+ }
55
+ if let Some ( query) = req. url . query ( ) {
56
+ if !question_mark {
57
+ url_str. push ( '?' ) ;
58
+ } else {
59
+ url_str. push ( '&' ) ;
60
+ }
61
+ url_str. push_str ( query) ;
55
62
}
56
63
let url = ctry ! ( req, Url :: parse( & url_str) ) ;
57
64
let ( status_code, max_age) = if permanent {
@@ -1776,6 +1783,11 @@ mod test {
1776
1783
"/some_random_crate/latest/some_random_crate/?search=some::path" ,
1777
1784
web,
1778
1785
) ?;
1786
+ assert_redirect (
1787
+ "/some_random_crate::some::path?go_to_first=true" ,
1788
+ "/some_random_crate/latest/some_random_crate/?search=some::path&go_to_first=true" ,
1789
+ web,
1790
+ ) ?;
1779
1791
1780
1792
assert_redirect (
1781
1793
"/std::some::path" ,
You can’t perform that action at this time.
0 commit comments