From d3b7b7e23a58e772194677b54672ff118ecc9093 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 3 Oct 2020 16:23:03 +0200 Subject: [PATCH] Enforce closing HTML tags to have a ">" character --- src/librustdoc/passes/html_tags.rs | 20 ++++++++++++++++++++ src/test/rustdoc-ui/invalid-html-tags.rs | 8 +++++++- src/test/rustdoc-ui/invalid-html-tags.stderr | 8 +++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index 4218717c436..ae4eac89b45 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -111,6 +111,26 @@ fn extract_tag( r.end += 1; } if is_closing { + // In case we have "" or even "". + if c != '>' { + if !c.is_whitespace() { + // It seems like it's not a valid HTML tag. + break; + } + let mut found = false; + for (new_pos, c) in text[pos..].char_indices() { + if !c.is_whitespace() { + if c == '>' { + r.end = range.start + new_pos + 1; + found = true; + } + break; + } + } + if !found { + break; + } + } drop_tag(tags, tag_name, r, f); } else { tags.push((tag_name, r)); diff --git a/src/test/rustdoc-ui/invalid-html-tags.rs b/src/test/rustdoc-ui/invalid-html-tags.rs index db97ab4456c..d878e390ca3 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.rs +++ b/src/test/rustdoc-ui/invalid-html-tags.rs @@ -23,7 +23,7 @@ pub fn foo() {} /// /// //~^ ERROR unopened HTML tag `hello` -pub fn f() {} +pub fn bar() {} ///
///

@@ -67,3 +67,9 @@ pub fn d() {} ///

/// pub fn e() {} + +// Closing tags need to have ">" at the end, otherwise it's not a closing tag! +///
+///
$DIR/invalid-html-tags.rs:73:5 + | +LL | ///