]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
report: encode cdata sections correctly
authorDarrick J. Wong <djwong@kernel.org>
Wed, 15 Mar 2023 00:53:04 +0000 (17:53 -0700)
committerZorro Lang <zlang@kernel.org>
Sun, 26 Mar 2023 14:04:05 +0000 (22:04 +0800)
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>
common/report

index be991b55f5d4aa8f2360a4daebe7e5f57a60d7f9..eb169175bc0e65ada6d4281140547a9e6e12ce04 100644 (file)
@@ -19,6 +19,11 @@ encode_xml()
                -e 's/"/\&quot;/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