Problem
Both defects fixed in the test report (#1249) exist in the coverage HTML report, which is a separate writer.
1. Filenames are joined and split on |
src/coverage/report_html.sh:92 builds each row as "$display_file|$hit|$executable|$pct|$safe_filename" and src/coverage/html_index.sh:319 splits it with IFS='|'. A source file whose name contains a pipe truncates:
$ bashunit --coverage --coverage-paths src/ --coverage-report-html cov t_test.sh
# console, correct:src/a|b.sh 1/ 1 lines (100%)
# cov/index.html:class="file-name">a< # should be a|b.shclass="file-path">./src/a< # should be ./src/a|b.sh
The coverage numbers are right; only the HTML display is wrong, and silently.
2. Filenames are written into the markup unescaped
$ ls src/'a<b>c.sh'
# cov/index.html:class="file-name">a<b>
The <b> is parsed as a tag and leaks into the rest of the document. & is more plausible in a real filename and produces invalid entity syntax (read&write.sh).
src/coverage/html_file.sh escapes the source lines it renders — its awk escape() covers &, <, >, which is right for element content. It is the filenames that go out raw, in both the index (link text, file path) and the per-file page (<title>, two spans).
Fix
Separate the row fields with US (0x1f) as the test report now does, and escape the filenames.
The escaping helper belongs in src/util/str.sh: util/index.sh is sourced before both coverage/ and reports/, so one bashunit::str::html_escape serves both and replaces the copy added to src/reports/html.sh in #1251 rather than leaving two.
Problem
Both defects fixed in the test report (#1249) exist in the coverage HTML report, which is a separate writer.
1. Filenames are joined and split on
|src/coverage/report_html.sh:92builds each row as"$display_file|$hit|$executable|$pct|$safe_filename"andsrc/coverage/html_index.sh:319splits it withIFS='|'. A source file whose name contains a pipe truncates:The coverage numbers are right; only the HTML display is wrong, and silently.
2. Filenames are written into the markup unescaped
The
<b>is parsed as a tag and leaks into the rest of the document.&is more plausible in a real filename and produces invalid entity syntax (read&write.sh).src/coverage/html_file.shescapes the source lines it renders — its awkescape()covers&,<,>, which is right for element content. It is the filenames that go out raw, in both the index (link text, file path) and the per-file page (<title>, two spans).Fix
Separate the row fields with US (0x1f) as the test report now does, and escape the filenames.
The escaping helper belongs in
src/util/str.sh:util/index.shis sourced before bothcoverage/andreports/, so onebashunit::str::html_escapeserves both and replaces the copy added tosrc/reports/html.shin #1251 rather than leaving two.