Skip to content

Commit

Permalink
Don't warn if the tag is nested inside a <script> or inside a <style>
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 3, 2020
1 parent b2321bb commit 30cabfd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librustdoc/passes/html_tags.rs
Expand Up @@ -48,8 +48,11 @@ fn drop_tag(
if let Some(pos) = tags.iter().rev().position(|(t, _)| *t == tag_name) {
// Because this is from a `rev` iterator, the position is reversed as well!
let pos = tags.len() - 1 - pos;
// If the tag is nested inside a "<script>", not warning should be emitted.
let should_not_warn =
tags.iter().take(pos + 1).any(|(at, _)| at == "script" || at == "style");
for (last_tag_name, last_tag_span) in tags.drain(pos + 1..) {
if ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name) {
if should_not_warn || ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name) {
continue;
}
// `tags` is used as a queue, meaning that everything after `pos` is included inside it.
Expand Down
22 changes: 22 additions & 0 deletions src/test/rustdoc-ui/invalid-html-tags.rs
Expand Up @@ -39,3 +39,25 @@ pub fn b() {}
/// <h3>
//~^ ERROR unclosed HTML tag `h3`
pub fn c() {}

// Unclosed tags shouldn't warn if they are nested inside a <script> elem.
/// <script>
/// <h3><div>
/// </script>
/// <script>
/// <div>
/// <p>
/// </div>
/// </script>
pub fn d() {}

// Unclosed tags shouldn't warn if they are nested inside a <style> elem.
/// <style>
/// <h3><div>
/// </style>
/// <style>
/// <div>
/// <p>
/// </div>
/// </style>
pub fn e() {}

0 comments on commit 30cabfd

Please sign in to comment.