Skip to content

Commit 6e797ff

Browse files
authored
Rollup merge of #68263 - ollie27:rustdoc_invalid_syntax_highlight_escape, r=GuillaumeGomez
rustdoc: HTML escape codeblocks which fail syntax highlighting r? @GuillaumeGomez
2 parents c0ff382 + baf2921 commit 6e797ff

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/librustdoc/html/highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn render_with_highlighting(
6565
Err(()) => {
6666
// If errors are encountered while trying to highlight, just emit
6767
// the unhighlighted source.
68-
write!(out, "<pre><code>{}</code></pre>", src).unwrap();
68+
write!(out, "<pre><code>{}</code></pre>", Escape(src)).unwrap();
6969
}
7070
}
7171

src/test/rustdoc/bad-codeblock-syntax.rs

+8
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ pub fn quux() {}
2525
/// \_
2626
/// ```
2727
pub fn ok() {}
28+
29+
// @has bad_codeblock_syntax/fn.escape.html
30+
// @has - '//*[@class="docblock"]/pre/code' '\_ <script>alert("not valid Rust");</script>'
31+
/// ```
32+
/// \_
33+
/// <script>alert("not valid Rust");</script>
34+
/// ```
35+
pub fn escape() {}

0 commit comments

Comments
 (0)