Skip to content

Commit

Permalink
rustdoc: HTML escape crate version
Browse files Browse the repository at this point in the history
As `--crate-version` accepts arbitrary strings they need to be escaped.
  • Loading branch information
ollie27 committed Mar 1, 2020
1 parent 3eeefc2 commit 3c97f8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustdoc/html/render.rs
Expand Up @@ -1313,7 +1313,8 @@ impl Context {
<p>Version {}</p>\
</div>\
<a id='all-types' href='index.html'><p>Back to index</p></a>",
crate_name, version
crate_name,
Escape(version),
)
} else {
String::new()
Expand Down Expand Up @@ -3974,7 +3975,7 @@ fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer) {
"<div class='block version'>\
<p>Version {}</p>\
</div>",
version
Escape(version)
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc/crate-version-escape.rs
@@ -0,0 +1,6 @@
// compile-flags: --crate-version=<script>alert("hi")</script> -Z unstable-options

#![crate_name = "foo"]

// @has 'foo/index.html' '//div[@class="block version"]/p' 'Version <script>alert("hi")</script>'
// @has 'foo/all.html' '//div[@class="block version"]/p' 'Version <script>alert("hi")</script>'

0 comments on commit 3c97f8a

Please sign in to comment.