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:
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 =
|
||||
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 <T>
|
||||
assert!(bar_ts_html.contains("<T>"));
|
||||
|
||||
let baz_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) {
|
||||
return 1;
|
||||
} else {
|
||||
|
|
|
@ -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('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">");
|
||||
|
||||
// TODO(kt3k): Add syntax highlight to source code
|
||||
format!(
|
||||
"<table class='coverage'>
|
||||
|
|
Loading…
Reference in a new issue