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> { 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> { + fn header( + &self, + output: &mut dyn Write, + extra_path: &str, + extra: &str, + ) -> Result<(), Box> { write!( output, r##" @@ -99,14 +104,14 @@ impl HTMLFormatter { Rust Compiler Error Index - - - + + + +{extra} "##, @@ -153,7 +158,22 @@ fn render_html(output_path: &Path, formatter: HTMLFormatter) -> Result<(), Box(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'; + }} + }} +}})()"# + ), + )?; formatter.title(&mut output_file, "Rust Compiler Error Index")?; write!(