Enforce closing HTML tags to have a ">" character
This commit is contained in:
parent
ca199b16e5
commit
d3b7b7e23a
3 changed files with 34 additions and 2 deletions
|
@ -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));
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue