mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(coverage): escape source code in html coverage report (#21531)
This commit is contained in:
parent
e9ab9ba9f0
commit
073e341faf
3 changed files with 9 additions and 2 deletions
|
@ -553,6 +553,8 @@ fn test_html_reporter() {
|
||||||
let bar_ts_html =
|
let bar_ts_html =
|
||||||
fs::read_to_string(tempdir.join("html").join("bar.ts.html")).unwrap();
|
fs::read_to_string(tempdir.join("html").join("bar.ts.html")).unwrap();
|
||||||
assert!(bar_ts_html.contains("<h1>Coverage report for bar.ts</h1>"));
|
assert!(bar_ts_html.contains("<h1>Coverage report for bar.ts</h1>"));
|
||||||
|
// Check <T> in source code is escaped to <T>
|
||||||
|
assert!(bar_ts_html.contains("<T>"));
|
||||||
|
|
||||||
let baz_index_html =
|
let baz_index_html =
|
||||||
fs::read_to_string(tempdir.join("html").join("baz").join("index.html"))
|
fs::read_to_string(tempdir.join("html").join("baz").join("index.html"))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export function bar(cond: boolean) {
|
export function bar<T>(cond: T) {
|
||||||
if (cond) {
|
if (cond) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -512,7 +512,7 @@ impl HtmlCoverageReporter {
|
||||||
/// Creates <table> of single file code coverage.
|
/// Creates <table> of single file code coverage.
|
||||||
pub fn create_html_code_table(
|
pub fn create_html_code_table(
|
||||||
&self,
|
&self,
|
||||||
file_text: &String,
|
file_text: &str,
|
||||||
report: &CoverageReport,
|
report: &CoverageReport,
|
||||||
) -> String {
|
) -> String {
|
||||||
let line_num = file_text.lines().count();
|
let line_num = file_text.lines().count();
|
||||||
|
@ -548,6 +548,11 @@ impl HtmlCoverageReporter {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
|
let file_text = file_text
|
||||||
|
.replace('&', "&")
|
||||||
|
.replace('<', "<")
|
||||||
|
.replace('>', ">");
|
||||||
|
|
||||||
// TODO(kt3k): Add syntax highlight to source code
|
// TODO(kt3k): Add syntax highlight to source code
|
||||||
format!(
|
format!(
|
||||||
"<table class='coverage'>
|
"<table class='coverage'>
|
||||||
|
|
Loading…
Add table
Reference in a new issue