Skip to content

Commit 4b271f3

Browse files
committed
rustdoc: Preserve query/fragment in redirects whenever possible.
We heavily rely on queries and fragments in the URL structure, so it is desired to preserve them even in the redirects. The generated redirect pages try to preserve them with scripts, which take precedence over the original `Refresh` metadata. Non-scripting browsers would continue to work (with no queries and fragments).
1 parent daa0745 commit 4b271f3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/librustdoc/html/layout.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,16 @@ r##"<!DOCTYPE html>
160160
}
161161

162162
pub fn redirect(dst: &mut io::Writer, url: &str) -> io::IoResult<()> {
163+
// <script> triggers a redirect before refresh, so this is fine.
163164
write!(dst,
164165
r##"<!DOCTYPE html>
165166
<html lang="en">
166167
<head>
167168
<meta http-equiv="refresh" content="0;URL={url}">
168169
</head>
169170
<body>
171+
<p>Redirecting to <a href="{url}">{url}</a>...</p>
172+
<script>location.replace("{url}" + location.search + location.hash);</script>
170173
</body>
171174
</html>"##,
172175
url = url,

0 commit comments

Comments
 (0)