From: Theodore Ts'o Date: Sat, 30 Sep 2017 03:46:21 +0000 (-0400) Subject: report: encode XML Character Entities in xUnit report X-Git-Tag: v2022.05.01~1848 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=285a1d2215fb7d093fa1cc8cac2805e586a0a1d8;p=xfstests-dev.git report: encode XML Character Entities in xUnit report Since the xUnit report is an XML document, special XML characters such as '<', '>', '&', etc. have to be encoded as "<", ">", etc. Otherwise programs parsing something like this: Will get choke the unescaped '<' character in the skipped message. Signed-off-by: Theodore Ts'o Cc: Dmitry Monakhov Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/common/report b/common/report index 15a63db8..bb689836 100644 --- a/common/report +++ b/common/report @@ -25,6 +25,15 @@ REPORT_ENV_LIST="$REPORT_ENV_LIST OVL_UPPER" REPORT_ENV_LIST="$REPORT_ENV_LIST OVL_LOWER" REPORT_ENV_LIST="$REPORT_ENV_LIST OVL_WORK" +encode_xml() +{ + sed -e 's/&/\&/g' \ + -e 's/>/\>/g' \ + -e 's/" >> $report else echo -e "\t\t" >> $report @@ -103,20 +112,20 @@ _xunit_make_testcase_report() if [ -s $seqres.full ]; then echo -e "\t\t" >> $report printf '>$report - cat $seqres.full | tr -dc '[:print:][:space:]' >>$report + cat $seqres.full | tr -dc '[:print:][:space:]' | encode_xml >>$report printf ']]>\n' >>$report echo -e "\t\t" >> $report fi if [ -f $seqres.dmesg ]; then echo -e "\t\t" >> $report printf '>$report - cat $seqres.dmesg | tr -dc '[:print:][:space:]' >>$report + cat $seqres.dmesg | tr -dc '[:print:][:space:]' | encode_xml >>$report printf ']]>\n' >>$report echo -e "\t\t" >> $report elif [ -s $seqres.out.bad ]; then echo -e "\t\t" >> $report printf '>$report - $diff $seq.out $seqres.out.bad >>$report + $diff $seq.out $seqres.out.bad | encode_xml >>$report printf ']]>\n' >>$report echo -e "\t\t" >> $report fi