Skip to content

Commit 30cabfd

Browse files
Don't warn if the tag is nested inside a <script> or inside a <style>
1 parent b2321bb commit 30cabfd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/librustdoc/passes/html_tags.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ fn drop_tag(
4848
if let Some(pos) = tags.iter().rev().position(|(t, _)| *t == tag_name) {
4949
// Because this is from a `rev` iterator, the position is reversed as well!
5050
let pos = tags.len() - 1 - pos;
51+
// If the tag is nested inside a "<script>", not warning should be emitted.
52+
let should_not_warn =
53+
tags.iter().take(pos + 1).any(|(at, _)| at == "script" || at == "style");
5154
for (last_tag_name, last_tag_span) in tags.drain(pos + 1..) {
52-
if ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name) {
55+
if should_not_warn || ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name) {
5356
continue;
5457
}
5558
// `tags` is used as a queue, meaning that everything after `pos` is included inside it.

src/test/rustdoc-ui/invalid-html-tags.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,25 @@ pub fn b() {}
3939
/// <h3>
4040
//~^ ERROR unclosed HTML tag `h3`
4141
pub fn c() {}
42+
43+
// Unclosed tags shouldn't warn if they are nested inside a <script> elem.
44+
/// <script>
45+
/// <h3><div>
46+
/// </script>
47+
/// <script>
48+
/// <div>
49+
/// <p>
50+
/// </div>
51+
/// </script>
52+
pub fn d() {}
53+
54+
// Unclosed tags shouldn't warn if they are nested inside a <style> elem.
55+
/// <style>
56+
/// <h3><div>
57+
/// </style>
58+
/// <style>
59+
/// <div>
60+
/// <p>
61+
/// </div>
62+
/// </style>
63+
pub fn e() {}

0 commit comments

Comments
 (0)