]> git.lizzy.rs Git - rust.git/commitdiff
Enforce closing HTML tags to have a ">" character
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 3 Oct 2020 14:23:03 +0000 (16:23 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 3 Oct 2020 14:23:03 +0000 (16:23 +0200)
src/librustdoc/passes/html_tags.rs
src/test/rustdoc-ui/invalid-html-tags.rs
src/test/rustdoc-ui/invalid-html-tags.stderr

index 4218717c4366cf7e31e50972d10b21a440146f53..ae4eac89b457af3e82a489a2c9a374d40cbf5bd0 100644 (file)
@@ -111,6 +111,26 @@ fn extract_tag(
                             r.end += 1;
                         }
                         if is_closing {
+                            // In case we have "</div >" or even "</div         >".
+                            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));
index db97ab4456cd0a902f454cf1a9a36490fa0ccfb4..d878e390ca33934c7a76b7fb20a20957a75d621d 100644 (file)
@@ -23,7 +23,7 @@ pub fn foo() {}
 /// </h1>
 /// </hello>
 //~^ ERROR unopened HTML tag `hello`
-pub fn f() {}
+pub fn bar() {}
 
 /// <div>
 ///    <br/> <p>
@@ -67,3 +67,9 @@ pub fn d() {}
 ///   </div>
 /// </style>
 pub fn e() {}
+
+// Closing tags need to have ">" at the end, otherwise it's not a closing tag!
+/// <div></div >
+/// <div></div
+//~^ ERROR unclosed HTML tag `div`
+pub fn f() {}
index caa5dd124c18ff035addaa9333f8627128413f84..11f176ff05cc6f0fb580b5d32588927fb1bab237 100644 (file)
@@ -70,5 +70,11 @@ error: unclosed HTML tag `script`
 LL | /// <script
    |     ^^^^^^
 
-error: aborting due to 11 previous errors
+error: unclosed HTML tag `div`
+  --> $DIR/invalid-html-tags.rs:73:5
+   |
+LL | /// <div></div
+   |     ^^^^^
+
+error: aborting due to 12 previous errors