]> git.lizzy.rs Git - rust.git/commitdiff
Don't warn if the tag is nested inside a <script> or inside a <style>
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 27 Sep 2020 14:15:26 +0000 (16:15 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 3 Oct 2020 12:16:24 +0000 (14:16 +0200)
src/librustdoc/passes/html_tags.rs
src/test/rustdoc-ui/invalid-html-tags.rs

index 79035ba79ffd1a4d6442ea8a5dbaff5653c1bb57..490e913fbde8bcf5fe870049699d3b8685cd1413 100644 (file)
@@ -48,8 +48,11 @@ fn drop_tag(
     if let Some(pos) = tags.iter().rev().position(|(t, _)| *t == tag_name) {
         // Because this is from a `rev` iterator, the position is reversed as well!
         let pos = tags.len() - 1 - pos;
+        // If the tag is nested inside a "<script>", not warning should be emitted.
+        let should_not_warn =
+            tags.iter().take(pos + 1).any(|(at, _)| at == "script" || at == "style");
         for (last_tag_name, last_tag_span) in tags.drain(pos + 1..) {
-            if ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name) {
+            if should_not_warn || ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name) {
                 continue;
             }
             // `tags` is used as a queue, meaning that everything after `pos` is included inside it.
index 51bbae2a0b64e1e86ca5ca62748c4cce75b05cdc..0dc2002bd39d563d8a748c602162938d6774d32d 100644 (file)
@@ -39,3 +39,25 @@ pub fn b() {}
 ///   <h3>
 //~^ ERROR unclosed HTML tag `h3`
 pub fn c() {}
+
+// Unclosed tags shouldn't warn if they are nested inside a <script> elem.
+/// <script>
+///   <h3><div>
+/// </script>
+/// <script>
+///   <div>
+///     <p>
+///   </div>
+/// </script>
+pub fn d() {}
+
+// Unclosed tags shouldn't warn if they are nested inside a <style> elem.
+/// <style>
+///   <h3><div>
+/// </style>
+/// <style>
+///   <div>
+///     <p>
+///   </div>
+/// </style>
+pub fn e() {}