Skip to content

Commit

Permalink
rustdoc: HTML escape codeblocks which fail syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
ollie27 committed Jan 15, 2020
1 parent 31dd4f4 commit baf2921
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustdoc/html/highlight.rs
Expand Up @@ -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();
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc/bad-codeblock-syntax.rs
Expand Up @@ -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() {}

0 comments on commit baf2921

Please sign in to comment.