Skip to content

Commit 111865a

Browse files
Emilgardissyphar
authored andcommitted
always parse with params
1 parent d5df7e4 commit 111865a

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

src/web/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -728,24 +728,24 @@ mod test {
728728
wrapper(|env| {
729729
let web = env.frontend();
730730
for krate in &["std", "alloc", "core", "proc_macro", "test"] {
731-
let target = format!("https://doc.rust-lang.org/stable/{}/", krate);
731+
let target = format!("https://doc.rust-lang.org/stable/{}/?", krate);
732732

733733
// with or without slash
734734
assert_redirect(&format!("/{}", krate), &target, web)?;
735735
assert_redirect(&format!("/{}/", krate), &target, web)?;
736736
}
737737

738-
let target = "https://doc.rust-lang.org/stable/proc_macro/";
738+
let target = "https://doc.rust-lang.org/stable/proc_macro/?";
739739
// with or without slash
740740
assert_redirect("/proc-macro", target, web)?;
741741
assert_redirect("/proc-macro/", target, web)?;
742742

743-
let target = "https://doc.rust-lang.org/nightly/nightly-rustc/";
743+
let target = "https://doc.rust-lang.org/nightly/nightly-rustc/?";
744744
// with or without slash
745745
assert_redirect("/rustc", target, web)?;
746746
assert_redirect("/rustc/", target, web)?;
747747

748-
let target = "https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/";
748+
let target = "https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/?";
749749
// with or without slash
750750
assert_redirect("/rustdoc", target, web)?;
751751
assert_redirect("/rustdoc/", target, web)?;

src/web/releases.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -607,17 +607,13 @@ pub fn search_handler(req: &mut Request) -> IronResult<Response> {
607607
let url = if matchver.rustdoc_status {
608608
let target_name = matchver.target_name;
609609
let path = format!("{base}/{krate}/{version}/{target_name}/");
610-
if queries.is_empty() {
611-
ctry!(req, Url::parse(&path))
612-
} else {
613-
ctry!(
610+
ctry!(
611+
req,
612+
Url::from_generic_url(ctry!(
614613
req,
615-
Url::from_generic_url(ctry!(
616-
req,
617-
iron::url::Url::parse_with_params(&path, queries)
618-
))
619-
)
620-
}
614+
iron::url::Url::parse_with_params(&path, queries)
615+
))
616+
)
621617
} else {
622618
ctry!(req, Url::parse(&format!("{base}/crate/{krate}/{version}")))
623619
};
@@ -865,7 +861,7 @@ mod tests {
865861

866862
assert_redirect(
867863
"/releases/search?query=some_random_crate&i-am-feeling-lucky=1",
868-
"/some_random_crate/1.0.0/some_random_crate/",
864+
"/some_random_crate/1.0.0/some_random_crate/?",
869865
web,
870866
)?;
871867
Ok(())

src/web/rustdoc.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,19 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
5353
if let Some(path) = path_in_crate {
5454
queries.insert("search".into(), path.into());
5555
}
56-
let url: iron::url::Url = req.url.clone().into();
57-
let query_pairs = url.query_pairs();
58-
queries.extend(query_pairs);
59-
let url = if queries.is_empty() {
60-
ctry!(req, iron::url::Url::parse(&url_str))
61-
} else {
62-
ctry!(req, iron::url::Url::parse_with_params(&url_str, queries))
63-
};
56+
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+
);
6464
let (status_code, max_age) = if permanent {
6565
(status::MovedPermanently, 86400)
6666
} else {
6767
(status::Found, 0)
6868
};
69-
let url = ctry!(req, Url::from_generic_url(url));
7069
let mut resp = Response::with((status_code, Redirect(url)));
7170
resp.headers
7271
.set(CacheControl(vec![CacheDirective::MaxAge(max_age)]));
@@ -866,8 +865,8 @@ mod test {
866865
"/dummy/0.3.0/all.html",
867866
web,
868867
)?;
869-
assert_redirect("/dummy/0.3.0/", base, web)?;
870-
assert_redirect("/dummy/0.3.0/index.html", base, web)?;
868+
assert_redirect("/dummy/0.3.0/", &format!("{}?", base), web)?;
869+
assert_redirect("/dummy/0.3.0/index.html", &format!("{}?", base), web)?;
871870
Ok(())
872871
});
873872
}
@@ -1184,7 +1183,7 @@ mod test {
11841183
.create()?;
11851184

11861185
let web = env.frontend();
1187-
assert_redirect("/fake%2Dcrate", "/fake-crate/latest/fake_crate/", web)?;
1186+
assert_redirect("/fake%2Dcrate", "/fake-crate/latest/fake_crate/?", web)?;
11881187

11891188
Ok(())
11901189
});
@@ -1214,37 +1213,37 @@ mod test {
12141213

12151214
let web = env.frontend();
12161215

1217-
assert_redirect("/dummy_dash", "/dummy-dash/latest/dummy_dash/", web)?;
1218-
assert_redirect("/dummy_dash/*", "/dummy-dash/0.2.0/dummy_dash/", web)?;
1219-
assert_redirect("/dummy_dash/0.1.0", "/dummy-dash/0.1.0/dummy_dash/", web)?;
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)?;
12201219
assert_redirect(
12211220
"/dummy-underscore",
1222-
"/dummy_underscore/latest/dummy_underscore/",
1221+
"/dummy_underscore/latest/dummy_underscore/?",
12231222
web,
12241223
)?;
12251224
assert_redirect(
12261225
"/dummy-underscore/*",
1227-
"/dummy_underscore/0.2.0/dummy_underscore/",
1226+
"/dummy_underscore/0.2.0/dummy_underscore/?",
12281227
web,
12291228
)?;
12301229
assert_redirect(
12311230
"/dummy-underscore/0.1.0",
1232-
"/dummy_underscore/0.1.0/dummy_underscore/",
1231+
"/dummy_underscore/0.1.0/dummy_underscore/?",
12331232
web,
12341233
)?;
12351234
assert_redirect(
12361235
"/dummy-mixed_separators",
1237-
"/dummy_mixed-separators/latest/dummy_mixed_separators/",
1236+
"/dummy_mixed-separators/latest/dummy_mixed_separators/?",
12381237
web,
12391238
)?;
12401239
assert_redirect(
12411240
"/dummy_mixed_separators/*",
1242-
"/dummy_mixed-separators/0.2.0/dummy_mixed_separators/",
1241+
"/dummy_mixed-separators/0.2.0/dummy_mixed_separators/?",
12431242
web,
12441243
)?;
12451244
assert_redirect(
12461245
"/dummy-mixed-separators/0.1.0",
1247-
"/dummy_mixed-separators/0.1.0/dummy_mixed_separators/",
1246+
"/dummy_mixed-separators/0.1.0/dummy_mixed_separators/?",
12481247
web,
12491248
)?;
12501249

0 commit comments

Comments
 (0)