Skip to content

Commit d3b7b7e

Browse files
Enforce closing HTML tags to have a ">" character
1 parent ca199b1 commit d3b7b7e

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/librustdoc/passes/html_tags.rs

+20
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ fn extract_tag(
111111
r.end += 1;
112112
}
113113
if is_closing {
114+
// In case we have "</div >" or even "</div >".
115+
if c != '>' {
116+
if !c.is_whitespace() {
117+
// It seems like it's not a valid HTML tag.
118+
break;
119+
}
120+
let mut found = false;
121+
for (new_pos, c) in text[pos..].char_indices() {
122+
if !c.is_whitespace() {
123+
if c == '>' {
124+
r.end = range.start + new_pos + 1;
125+
found = true;
126+
}
127+
break;
128+
}
129+
}
130+
if !found {
131+
break;
132+
}
133+
}
114134
drop_tag(tags, tag_name, r, f);
115135
} else {
116136
tags.push((tag_name, r));

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn foo() {}
2323
/// </h1>
2424
/// </hello>
2525
//~^ ERROR unopened HTML tag `hello`
26-
pub fn f() {}
26+
pub fn bar() {}
2727

2828
/// <div>
2929
/// <br/> <p>
@@ -67,3 +67,9 @@ pub fn d() {}
6767
/// </div>
6868
/// </style>
6969
pub fn e() {}
70+
71+
// Closing tags need to have ">" at the end, otherwise it's not a closing tag!
72+
/// <div></div >
73+
/// <div></div
74+
//~^ ERROR unclosed HTML tag `div`
75+
pub fn f() {}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,11 @@ error: unclosed HTML tag `script`
7070
LL | /// <script
7171
| ^^^^^^
7272

73-
error: aborting due to 11 previous errors
73+
error: unclosed HTML tag `div`
74+
--> $DIR/invalid-html-tags.rs:73:5
75+
|
76+
LL | /// <div></div
77+
| ^^^^^
78+
79+
error: aborting due to 12 previous errors
7480

0 commit comments

Comments
 (0)