From 285a1d2215fb7d093fa1cc8cac2805e586a0a1d8 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 29 Sep 2017 23:46:21 -0400 Subject: [PATCH] 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 --- common/report | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 -- 2.30.2