diff options
author | Darrick J. Wong <djwong@kernel.org> | 2023-03-14 17:53:04 -0700 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2023-03-26 22:04:05 +0800 |
commit | 77bedb6a7db2c4727fe033819bf3e03a1e8bb06b (patch) | |
tree | 34c9cb9cdb8b9e52d8b9de3ffa6824d4636f39e8 /common | |
parent | a8963ceb25ef375bdc8cd89bdcaf87f72d9cc7ac (diff) |
report: encode cdata sections correctly
The XML report format captures the contents of .full and .out.bad files
in CDATA sections. CDATA sections are supposed to be a stream of
verbatim data, terminated with a "]]>". Hence XML entities such as
quotation marks and angle brackes should not be escaped, and an actual
bracket-bracket-gt sequence in those files /does/ need escaping.
Create a separate filtering function so that these files are encoded
properly.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/report | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/common/report b/common/report index be991b55..eb169175 100644 --- a/common/report +++ b/common/report @@ -19,6 +19,11 @@ encode_xml() -e 's/"/\"/g' } +encode_cdata() +{ + cat -v | sed -e 's/]]>/]]]]><![CDATA[>/g' +} + # # Xunit format report functions _xunit_add_property() @@ -128,7 +133,7 @@ _xunit_make_testcase_report() if [ -z "$quiet" -a -s "$full_file" ]; then echo -e "\t\t<system-out>" >> $report printf '<![CDATA[\n' >>$report - cat "$full_file" | tr -dc '[:print:][:space:]' | encode_xml >>$report + cat "$full_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report printf ']]>\n' >>$report echo -e "\t\t</system-out>" >> $report fi @@ -137,13 +142,13 @@ _xunit_make_testcase_report() elif [ -f "$dmesg_file" ]; then echo -e "\t\t<system-err>" >> $report printf '<![CDATA[\n' >>$report - cat "$dmesg_file" | tr -dc '[:print:][:space:]' | encode_xml >>$report + cat "$dmesg_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report printf ']]>\n' >>$report echo -e "\t\t</system-err>" >> $report elif [ -s "$outbad_file" ]; then echo -e "\t\t<system-err>" >> $report printf '<![CDATA[\n' >>$report - $diff "$out_src" "$outbad_file" | encode_xml >>$report + $diff "$out_src" "$outbad_file" | encode_cdata >>$report printf ']]>\n' >>$report echo -e "\t\t</system-err>" >> $report fi |