fix(coverage): HTML validation errors in coverage explorer (#29497)

Closes #29493
This commit is contained in:
Asher Gomez 2025-05-29 17:48:11 +10:00 committed by GitHub
parent ab9673dcc1
commit f9bb8241ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 8 deletions

View file

@ -505,7 +505,7 @@ impl HtmlCoverageReporter {
let footer = self.create_html_footer(timestamp); let footer = self.create_html_footer(timestamp);
format!( format!(
"<!doctype html> "<!doctype html>
<html> <html lang='en-US'>
{head} {head}
<body> <body>
<div class='wrapper'> <div class='wrapper'>
@ -530,7 +530,7 @@ impl HtmlCoverageReporter {
<meta charset='utf-8'> <meta charset='utf-8'>
<title>{title}</title> <title>{title}</title>
<style>{style_css}</style> <style>{style_css}</style>
<meta name='viewport' content='width=device-width, initial-scale=1' /> <meta name='viewport' content='width=device-width, initial-scale=1'>
</head>" </head>"
) )
} }
@ -658,7 +658,7 @@ impl HtmlCoverageReporter {
) -> String { ) -> String {
let line_num = file_text.lines().count(); let line_num = file_text.lines().count();
let line_count = (1..line_num + 1) let line_count = (1..line_num + 1)
.map(|i| format!("<a name='L{i}'></a><a href='#L{i}'>{i}</a>")) .map(|i| format!("<a href='#L{i}' id='L{i}'>{i}</a>"))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("\n");
let line_coverage = (0..line_num) let line_coverage = (0..line_num)
@ -667,12 +667,12 @@ impl HtmlCoverageReporter {
report.found_lines.iter().find(|(line, _)| i == *line) report.found_lines.iter().find(|(line, _)| i == *line)
{ {
if *count == 0 { if *count == 0 {
"<span class='cline-any cline-no'>&nbsp</span>".to_string() "<span class='cline-any cline-no'>&nbsp;</span>".to_string()
} else { } else {
format!("<span class='cline-any cline-yes' title='This line is covered {count} time{}'>x{count}</span>", if *count > 1 { "s" } else { "" }) format!("<span class='cline-any cline-yes' title='This line is covered {count} time{}'>x{count}</span>", if *count > 1 { "s" } else { "" })
} }
} else { } else {
"<span class='cline-any cline-neutral'>&nbsp</span>".to_string() "<span class='cline-any cline-neutral'>&nbsp;</span>".to_string()
} }
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()

View file

@ -557,8 +557,7 @@ fn test_html_reporter() {
// Check <T> in source code is escaped to &lt;T&gt; // Check <T> in source code is escaped to &lt;T&gt;
assert_contains!(bar_ts_html, "&lt;T&gt;"); assert_contains!(bar_ts_html, "&lt;T&gt;");
// Check that line anchors are correctly referenced by line number links // Check that line anchors are correctly referenced by line number links
assert_contains!(bar_ts_html, "<a name='L1'></a>"); assert_contains!(bar_ts_html, "<a href='#L1' id='L1'>1</a>");
assert_contains!(bar_ts_html, "<a href='#L1'>1</a>");
let baz_index_html = tempdir let baz_index_html = tempdir
.join("html") .join("html")

View file

@ -1,2 +1,2 @@
<!doctype html> <!doctype html>
<html>[WILDCARD]</html> <html lang='en-US'>[WILDCARD]</html>