rustdoc: HTML escape crate version

As `--crate-version` accepts arbitrary strings they need to be escaped.
This commit is contained in:
Oliver Middleton 2020-02-29 23:39:26 +00:00
parent 3eeefc21f1
commit 3c97f8ad12
2 changed files with 9 additions and 2 deletions

View File

@ -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()
@ -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)
);
}
}

View File

@ -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>'