Skip to content

Commit f3a85cf

Browse files
committed
rollup merge of #19513: lifthrasiir/rustdoc-fat-redirect
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). (This in turn solves a number of semi-broken links to the source code, which are actually linked to redirect pages.)
2 parents 33e96be + 4b271f3 commit f3a85cf

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)