about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/html/markdown.rs5
-rw-r--r--src/librustdoc/html/markdown/tests.rs12
2 files changed, 13 insertions, 4 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 908e292d968..783b8b2db46 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -34,6 +34,7 @@ use std::str;
 use crate::clean::RenderedLink;
 use crate::doctest;
 use crate::html::escape::Escape;
+use crate::html::format::Buffer;
 use crate::html::highlight;
 use crate::html::toc::TocBuilder;
 
@@ -41,8 +42,6 @@ use pulldown_cmark::{
     html, BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag,
 };
 
-use super::format::Buffer;
-
 #[cfg(test)]
 mod tests;
 
@@ -1086,7 +1085,7 @@ fn markdown_summary_with_limit(
     let mut stopped_early = false;
 
     fn push(s: &mut String, text_length: &mut usize, text: &str) {
-        s.push_str(text);
+        write!(s, "{}", Escape(text)).unwrap();
         *text_length += text.len();
     }
 
diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs
index d10da64ccfa..1e4bdc2d151 100644
--- a/src/librustdoc/html/markdown/tests.rs
+++ b/src/librustdoc/html/markdown/tests.rs
@@ -234,7 +234,17 @@ fn test_short_markdown_summary() {
     t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
     t("dud [link]", "dud [link]");
     t("code `let x = i32;` ...", "code <code>let x = i32;</code> …");
-    t("type `Type<'static>` ...", "type <code>Type<'static></code> …");
+    t("type `Type<'static>` ...", "type <code>Type&lt;&#39;static&gt;</code> …");
+    // Test to ensure escaping and length-limiting work well together.
+    // The output should be limited based on the input length,
+    // rather than the output, because escaped versions of characters
+    // are usually longer than how the character is actually displayed.
+    t(
+        "& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &",
+        "&amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; \
+         &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; \
+         &amp; &amp; &amp; &amp; &amp; …",
+    );
     t("# top header", "top header");
     t("# top header\n\nfollowed by a paragraph", "top header");
     t("## header", "header");