Skip to content

Commit

Permalink
Enforce closing HTML tags to have a ">" character
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 3, 2020
1 parent ca199b1 commit d3b7b7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/librustdoc/passes/html_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 7 additions & 1 deletion src/test/rustdoc-ui/invalid-html-tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn foo() {}
/// </h1>
/// </hello>
//~^ ERROR unopened HTML tag `hello`
pub fn f() {}
pub fn bar() {}

/// <div>
/// <br/> <p>
Expand Down Expand Up @@ -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() {}
8 changes: 7 additions & 1 deletion src/test/rustdoc-ui/invalid-html-tags.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d3b7b7e

Please sign in to comment.