diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index fb6bdcdc9f48b..aa52b769c38ed 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -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, "
{}
", src).unwrap(); + write!(out, "
{}
", Escape(src)).unwrap(); } } diff --git a/src/test/rustdoc/bad-codeblock-syntax.rs b/src/test/rustdoc/bad-codeblock-syntax.rs index 0ab2f68fcdebe..ae8fbe4a2a800 100644 --- a/src/test/rustdoc/bad-codeblock-syntax.rs +++ b/src/test/rustdoc/bad-codeblock-syntax.rs @@ -25,3 +25,11 @@ pub fn quux() {} /// \_ /// ``` pub fn ok() {} + +// @has bad_codeblock_syntax/fn.escape.html +// @has - '//*[@class="docblock"]/pre/code' '\_ ' +/// ``` +/// \_ +/// +/// ``` +pub fn escape() {}