Escape item search summaries

I noticed that `Pin::new()`'s search summary looked off, and I realized
that the reason is that it has inline code containing `Pin<P>`, which is
not escaped and thus renders as a paragraph tag!
This commit is contained in:
Noah Lev 2021-07-04 19:22:24 -07:00
parent e742158ef5
commit 4ad2d68602
2 changed files with 13 additions and 4 deletions

View File

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

View File

@ -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");