Skip to content

Commit 3c97f8a

Browse files
committed
rustdoc: HTML escape crate version
As `--crate-version` accepts arbitrary strings they need to be escaped.
1 parent 3eeefc2 commit 3c97f8a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/librustdoc/html/render.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,8 @@ impl Context {
13131313
<p>Version {}</p>\
13141314
</div>\
13151315
<a id='all-types' href='index.html'><p>Back to index</p></a>",
1316-
crate_name, version
1316+
crate_name,
1317+
Escape(version),
13171318
)
13181319
} else {
13191320
String::new()
@@ -3974,7 +3975,7 @@ fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer) {
39743975
"<div class='block version'>\
39753976
<p>Version {}</p>\
39763977
</div>",
3977-
version
3978+
Escape(version)
39783979
);
39793980
}
39803981
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// compile-flags: --crate-version=<script>alert("hi")</script> -Z unstable-options
2+
3+
#![crate_name = "foo"]
4+
5+
// @has 'foo/index.html' '//div[@class="block version"]/p' 'Version <script>alert("hi")</script>'
6+
// @has 'foo/all.html' '//div[@class="block version"]/p' 'Version <script>alert("hi")</script>'

0 commit comments

Comments
 (0)