diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-07-30 22:50:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-30 22:50:57 +0200 |
| commit | 852bf84c7baae184de43e9f3a7f7011c679d1aa7 (patch) | |
| tree | be09890a8e285f064d7c7d0a5b5de613ffbd145c | |
| parent | 44c4b4a0e709c01ece25cd896dd70d9becf62c6e (diff) | |
| parent | ad197e414c7dee64287b7f59b7ee3567a7f05927 (diff) | |
| download | rust-852bf84c7baae184de43e9f3a7f7011c679d1aa7.tar.gz rust-852bf84c7baae184de43e9f3a7f7011c679d1aa7.zip | |
Rollup merge of #99873 - notriddle:notriddle/invalid-html-tags-webcomponents, r=GuillaumeGomezp
rustdoc: align invalid-html-tags lint with commonmark spec
| -rw-r--r-- | src/librustdoc/passes/html_tags.rs | 10 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/invalid-html-tags.rs | 6 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/invalid-html-tags.stderr | 14 |
3 files changed, 28 insertions, 2 deletions
diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index d8ad299c3d3..f3a3c853cac 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -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, @@ -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() { diff --git a/src/test/rustdoc-ui/invalid-html-tags.rs b/src/test/rustdoc-ui/invalid-html-tags.rs index cec44b6d2ca..0f9d2e4b35d 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.rs +++ b/src/test/rustdoc-ui/invalid-html-tags.rs @@ -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() {} diff --git a/src/test/rustdoc-ui/invalid-html-tags.stderr b/src/test/rustdoc-ui/invalid-html-tags.stderr index 335e100c89d..24a455576e8 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.stderr +++ b/src/test/rustdoc-ui/invalid-html-tags.stderr @@ -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 |
