diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-08-23 21:44:25 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-08-23 21:44:29 +0200 |
| commit | c664a36033f2f948cb29339068c3ecd2d6728f8b (patch) | |
| tree | 7418bb6bfa5550bd33b5912c9b3cfa7246f90343 | |
| parent | 8ad36c45f8116c80cda018e63b9db6862e73a87d (diff) | |
| download | rust-c664a36033f2f948cb29339068c3ecd2d6728f8b.tar.gz rust-c664a36033f2f948cb29339068c3ecd2d6728f8b.zip | |
Handle error code hash by redirecting to the correct error code page
| -rw-r--r-- | src/tools/error_index_generator/main.rs | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 22243f9fc9d..68c46700361 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -59,7 +59,7 @@ impl HTMLFormatter { ) -> Result<(), Box<dyn Error>> { let mut output_file = File::create(parent_dir.join(err_code).with_extension("html"))?; - self.header(&mut output_file, "../")?; + self.header(&mut output_file, "../", "")?; self.title(&mut output_file, &format!("Error code {}", err_code))?; let mut id_map = IdMap::new(); @@ -90,7 +90,12 @@ impl HTMLFormatter { self.footer(&mut output_file) } - fn header(&self, output: &mut dyn Write, extra: &str) -> Result<(), Box<dyn Error>> { + fn header( + &self, + output: &mut dyn Write, + extra_path: &str, + extra: &str, + ) -> Result<(), Box<dyn Error>> { write!( output, r##"<!DOCTYPE html> @@ -99,14 +104,14 @@ impl HTMLFormatter { <title>Rust Compiler Error Index</title> <meta charset="utf-8"> <!-- Include rust.css after light.css so its rules take priority. --> -<link rel="stylesheet" type="text/css" href="{extra}rustdoc{suffix}.css"/> -<link rel="stylesheet" type="text/css" href="{extra}light{suffix}.css"/> -<link rel="stylesheet" type="text/css" href="{extra}rust.css"/> +<link rel="stylesheet" type="text/css" href="{extra_path}rustdoc{suffix}.css"/> +<link rel="stylesheet" type="text/css" href="{extra_path}light{suffix}.css"/> +<link rel="stylesheet" type="text/css" href="{extra_path}rust.css"/> <style> .error-undescribed {{ display: none; }} -</style> +</style>{extra} </head> <body> "##, @@ -153,7 +158,22 @@ fn render_html(output_path: &Path, formatter: HTMLFormatter) -> Result<(), Box<d create_dir_all(&parent)?; } - formatter.header(&mut output_file, "")?; + formatter.header( + &mut output_file, + "", + &format!( + r#"<script>(function() {{ + if (window.location.hash) {{ + let code = window.location.hash.replace(/^#/, ''); + // We have to make sure this pattern matches to avoid inadvertently creating an + // open redirect. + if (/^E[0-9]+$/.test(code)) {{ + window.location = './{error_codes_dir}/' + code + '.html'; + }} + }} +}})()</script>"# + ), + )?; formatter.title(&mut output_file, "Rust Compiler Error Index")?; write!( |
