Skip to content

Commit 03e9ae9

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Keep URL query when going to the latest version
1 parent 99e4b1a commit 03e9ae9

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/web/rustdoc.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
376376
.is_prerelease();
377377

378378
// If the requested crate version is the most recent, use it to build the url
379-
let latest_path = if is_latest_version {
379+
let mut latest_path = if is_latest_version {
380380
format!("/{}/{}", name, latest_version)
381381

382382
// If the requested version is not the latest, then find the path of the latest version for the `Go to latest` link
@@ -394,6 +394,10 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
394394
} else {
395395
format!("/crate/{}/{}", name, latest_version)
396396
};
397+
if let Some(query) = req.url.query() {
398+
latest_path.push('?');
399+
latest_path.push_str(query);
400+
}
397401

398402
// The path within this crate version's rustdoc output
399403
let inner_path = {
@@ -1541,4 +1545,28 @@ mod test {
15411545
)
15421546
})
15431547
}
1548+
1549+
#[test]
1550+
fn test_latest_version_keeps_query() {
1551+
wrapper(|env| {
1552+
env.fake_release()
1553+
.name("tungstenite")
1554+
.version("0.10.0")
1555+
.rustdoc_file("tungstenite/index.html")
1556+
.create()?;
1557+
env.fake_release()
1558+
.name("tungstenite")
1559+
.version("0.11.0")
1560+
.rustdoc_file("tungstenite/index.html")
1561+
.create()?;
1562+
assert_eq!(
1563+
latest_version_redirect(
1564+
"/tungstenite/0.10.0/tungstenite/?search=String%20-%3E%20Message",
1565+
env.frontend()
1566+
)?,
1567+
"/tungstenite/0.11.0/tungstenite/index.html?search=String%20-%3E%20Message",
1568+
);
1569+
Ok(())
1570+
});
1571+
}
15441572
}

0 commit comments

Comments
 (0)