diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 6a23b230e1224..92db95eae3248 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1313,7 +1313,8 @@ impl Context {
Version {}
\
\
Back to index
",
- 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) {
"",
- version
+ Escape(version)
);
}
}
diff --git a/src/test/rustdoc/crate-version-escape.rs b/src/test/rustdoc/crate-version-escape.rs
new file mode 100644
index 0000000000000..2f91eea339b39
--- /dev/null
+++ b/src/test/rustdoc/crate-version-escape.rs
@@ -0,0 +1,6 @@
+// compile-flags: --crate-version= -Z unstable-options
+
+#![crate_name = "foo"]
+
+// @has 'foo/index.html' '//div[@class="block version"]/p' 'Version '
+// @has 'foo/all.html' '//div[@class="block version"]/p' 'Version '