Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/librustdoc/passes/html_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ fn extract_path_backwards(text: &str, end_pos: usize) -> Option<usize> {
if current_pos == end_pos { None } else { Some(current_pos) }
}

fn is_valid_for_html_tag_name(c: char, is_empty: bool) -> bool {
// https://spec.commonmark.org/0.30/#raw-html
//
// > A tag name consists of an ASCII letter followed by zero or more ASCII letters, digits, or
// > hyphens (-).
c.is_ascii_alphabetic() || !is_empty && (c == '-' || c.is_ascii_digit())
}

fn extract_html_tag(
tags: &mut Vec<(String, Range<usize>)>,
text: &str,
Expand All @@ -117,7 +125,7 @@ fn extract_html_tag(
// Checking if this is a closing tag (like `</a>` for `<a>`).
if c == '/' && tag_name.is_empty() {
is_closing = true;
} else if c.is_ascii_alphanumeric() {
} else if is_valid_for_html_tag_name(c, tag_name.is_empty()) {
tag_name.push(c);
} else {
if !tag_name.is_empty() {
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/invalid-html-tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ pub fn j() {}
/// <Vec<_> shouldn't warn!
/// ``````
pub fn k() {}

/// Web Components style <dashed-tags>
//~^ ERROR unclosed HTML tag `dashed-tags`
/// Web Components style </unopened-tag>
//~^ ERROR unopened HTML tag `unopened-tag`
pub fn m() {}
14 changes: 13 additions & 1 deletion src/test/rustdoc-ui/invalid-html-tags.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,17 @@ error: Unclosed HTML comment
LL | /// <!--
| ^^^

error: aborting due to 13 previous errors
error: unopened HTML tag `unopened-tag`
--> $DIR/invalid-html-tags.rs:114:26
|
LL | /// Web Components style </unopened-tag>
| ^^^^^^^^^^^^^^^

error: unclosed HTML tag `dashed-tags`
--> $DIR/invalid-html-tags.rs:112:26
|
LL | /// Web Components style <dashed-tags>
| ^^^^^^^^^^^^^

error: aborting due to 15 previous errors