rustdoc: HTML escape codeblocks which fail syntax highlighting

This commit is contained in:
Oliver Middleton 2020-01-15 22:42:04 +00:00
parent 31dd4f4acb
commit baf2921ebc
2 changed files with 9 additions and 1 deletions

View File

@ -65,7 +65,7 @@ pub fn render_with_highlighting(
Err(()) => {
// If errors are encountered while trying to highlight, just emit
// the unhighlighted source.
write!(out, "<pre><code>{}</code></pre>", src).unwrap();
write!(out, "<pre><code>{}</code></pre>", Escape(src)).unwrap();
}
}

View File

@ -25,3 +25,11 @@ pub fn quux() {}
/// \_
/// ```
pub fn ok() {}
// @has bad_codeblock_syntax/fn.escape.html
// @has - '//*[@class="docblock"]/pre/code' '\_ <script>alert("not valid Rust");</script>'
/// ```
/// \_
/// <script>alert("not valid Rust");</script>
/// ```
pub fn escape() {}