Skip to content

Escape item search summaries #87331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ 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;

use pulldown_cmark::{
html, BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag,
};

use super::format::Buffer;

#[cfg(test)]
mod tests;

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

Expand Down
12 changes: 11 additions & 1 deletion src/librustdoc/html/markdown/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down