@@ -6,7 +6,8 @@ use crate::{
6
6
utils,
7
7
web:: {
8
8
crate_details:: CrateDetails , csp:: Csp , error:: Nope , file:: File , match_version,
9
- metrics:: RenderingTimesRecorder , redirect_base, MatchSemver , MetaData ,
9
+ metrics:: RenderingTimesRecorder , parse_url_with_params, redirect_base, MatchSemver ,
10
+ MetaData ,
10
11
} ,
11
12
Config , Metrics , Storage ,
12
13
} ;
@@ -22,7 +23,11 @@ use lol_html::errors::RewritingError;
22
23
use once_cell:: sync:: Lazy ;
23
24
use router:: Router ;
24
25
use serde:: Serialize ;
25
- use std:: { collections:: HashMap , fmt:: Write , path:: Path } ;
26
+ use std:: {
27
+ collections:: { BTreeMap , HashMap } ,
28
+ fmt:: Write ,
29
+ path:: Path ,
30
+ } ;
26
31
27
32
static DOC_RUST_LANG_ORG_REDIRECTS : Lazy < HashMap < & str , & str > > = Lazy :: new ( || {
28
33
HashMap :: from ( [
@@ -46,21 +51,12 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
46
51
permanent : bool ,
47
52
path_in_crate : Option < & str > ,
48
53
) -> IronResult < Response > {
49
- let mut queries: std:: collections:: BTreeMap <
50
- std:: borrow:: Cow < ' _ , str > ,
51
- std:: borrow:: Cow < ' _ , str > ,
52
- > = std:: collections:: BTreeMap :: new ( ) ;
54
+ let mut queries = BTreeMap :: new ( ) ;
53
55
if let Some ( path) = path_in_crate {
54
56
queries. insert ( "search" . into ( ) , path. into ( ) ) ;
55
57
}
56
58
queries. extend ( req. url . as_ref ( ) . query_pairs ( ) ) ;
57
- let url = ctry ! (
58
- req,
59
- Url :: from_generic_url( ctry!(
60
- req,
61
- iron:: url:: Url :: parse_with_params( & url_str, queries)
62
- ) )
63
- ) ;
59
+ let url = ctry ! ( req, parse_url_with_params( & url_str, queries) ) ;
64
60
let ( status_code, max_age) = if permanent {
65
61
( status:: MovedPermanently , 86400 )
66
62
} else {
@@ -865,8 +861,8 @@ mod test {
865
861
"/dummy/0.3.0/all.html" ,
866
862
web,
867
863
) ?;
868
- assert_redirect ( "/dummy/0.3.0/" , & format ! ( "{}?" , base) , web) ?;
869
- assert_redirect ( "/dummy/0.3.0/index.html" , & format ! ( "{}?" , base) , web) ?;
864
+ assert_redirect ( "/dummy/0.3.0/" , base, web) ?;
865
+ assert_redirect ( "/dummy/0.3.0/index.html" , base, web) ?;
870
866
Ok ( ( ) )
871
867
} ) ;
872
868
}
@@ -1183,7 +1179,7 @@ mod test {
1183
1179
. create ( ) ?;
1184
1180
1185
1181
let web = env. frontend ( ) ;
1186
- assert_redirect ( "/fake%2Dcrate" , "/fake-crate/latest/fake_crate/? " , web) ?;
1182
+ assert_redirect ( "/fake%2Dcrate" , "/fake-crate/latest/fake_crate/" , web) ?;
1187
1183
1188
1184
Ok ( ( ) )
1189
1185
} ) ;
@@ -1213,37 +1209,37 @@ mod test {
1213
1209
1214
1210
let web = env. frontend ( ) ;
1215
1211
1216
- assert_redirect ( "/dummy_dash" , "/dummy-dash/latest/dummy_dash/? " , web) ?;
1217
- assert_redirect ( "/dummy_dash/*" , "/dummy-dash/0.2.0/dummy_dash/? " , web) ?;
1218
- assert_redirect ( "/dummy_dash/0.1.0" , "/dummy-dash/0.1.0/dummy_dash/? " , web) ?;
1212
+ assert_redirect ( "/dummy_dash" , "/dummy-dash/latest/dummy_dash/" , web) ?;
1213
+ assert_redirect ( "/dummy_dash/*" , "/dummy-dash/0.2.0/dummy_dash/" , web) ?;
1214
+ assert_redirect ( "/dummy_dash/0.1.0" , "/dummy-dash/0.1.0/dummy_dash/" , web) ?;
1219
1215
assert_redirect (
1220
1216
"/dummy-underscore" ,
1221
- "/dummy_underscore/latest/dummy_underscore/? " ,
1217
+ "/dummy_underscore/latest/dummy_underscore/" ,
1222
1218
web,
1223
1219
) ?;
1224
1220
assert_redirect (
1225
1221
"/dummy-underscore/*" ,
1226
- "/dummy_underscore/0.2.0/dummy_underscore/? " ,
1222
+ "/dummy_underscore/0.2.0/dummy_underscore/" ,
1227
1223
web,
1228
1224
) ?;
1229
1225
assert_redirect (
1230
1226
"/dummy-underscore/0.1.0" ,
1231
- "/dummy_underscore/0.1.0/dummy_underscore/? " ,
1227
+ "/dummy_underscore/0.1.0/dummy_underscore/" ,
1232
1228
web,
1233
1229
) ?;
1234
1230
assert_redirect (
1235
1231
"/dummy-mixed_separators" ,
1236
- "/dummy_mixed-separators/latest/dummy_mixed_separators/? " ,
1232
+ "/dummy_mixed-separators/latest/dummy_mixed_separators/" ,
1237
1233
web,
1238
1234
) ?;
1239
1235
assert_redirect (
1240
1236
"/dummy_mixed_separators/*" ,
1241
- "/dummy_mixed-separators/0.2.0/dummy_mixed_separators/? " ,
1237
+ "/dummy_mixed-separators/0.2.0/dummy_mixed_separators/" ,
1242
1238
web,
1243
1239
) ?;
1244
1240
assert_redirect (
1245
1241
"/dummy-mixed-separators/0.1.0" ,
1246
- "/dummy_mixed-separators/0.1.0/dummy_mixed_separators/? " ,
1242
+ "/dummy_mixed-separators/0.1.0/dummy_mixed_separators/" ,
1247
1243
web,
1248
1244
) ?;
1249
1245
0 commit comments