1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(coverage): escape source code in html coverage report (#21531)

This commit is contained in:
Yoshiya Hinosawa 2023-12-11 19:24:20 +09:00 committed by GitHub
parent e9ab9ba9f0
commit 073e341faf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View file

@ -553,6 +553,8 @@ fn test_html_reporter() {
let bar_ts_html =
fs::read_to_string(tempdir.join("html").join("bar.ts.html")).unwrap();
assert!(bar_ts_html.contains("<h1>Coverage report for bar.ts</h1>"));
// Check <T> in source code is escaped to &lt;T&gt;
assert!(bar_ts_html.contains("&lt;T&gt;"));
let baz_index_html =
fs::read_to_string(tempdir.join("html").join("baz").join("index.html"))

View file

@ -1,4 +1,4 @@
export function bar(cond: boolean) {
export function bar<T>(cond: T) {
if (cond) {
return 1;
} else {

View file

@ -512,7 +512,7 @@ impl HtmlCoverageReporter {
/// Creates <table> of single file code coverage.
pub fn create_html_code_table(
&self,
file_text: &String,
file_text: &str,
report: &CoverageReport,
) -> String {
let line_num = file_text.lines().count();
@ -548,6 +548,11 @@ impl HtmlCoverageReporter {
.collect::<Vec<_>>()
.join("\n");
let file_text = file_text
.replace('&', "&amp;")
.replace('<', "&lt;")
.replace('>', "&gt;");
// TODO(kt3k): Add syntax highlight to source code
format!(
"<table class='coverage'>