libcheck: Escape strings in the generated xml files
authorThibault Saunier <thibault.saunier@collabora.com>
Tue, 23 Jul 2013 19:39:53 +0000 (15:39 -0400)
committerThibault Saunier <thibault.saunier@collabora.com>
Tue, 23 Jul 2013 20:02:01 +0000 (16:02 -0400)
This is copy pasted from upstream libcheck

libs/gst/check/libcheck/check_print.c

index f170d60..e29aa7b 100644 (file)
@@ -106,6 +106,38 @@ tr_fprint (FILE * file, TestResult * tr, enum print_output print_mode)
   }
 }
 
+static void
+fprint_xml_esc (FILE * file, const char *str)
+{
+  for (; *str != '\0'; str++) {
+
+    switch (*str) {
+
+        /* handle special characters that must be escaped */
+      case '"':
+        fputs ("&quot;", file);
+        break;
+      case '\'':
+        fputs ("&apos;", file);
+        break;
+      case '<':
+        fputs ("&lt;", file);
+        break;
+      case '>':
+        fputs ("&gt;", file);
+        break;
+      case '&':
+        fputs ("&amp;", file);
+        break;
+
+        /* regular characters, print as is */
+      default:
+        fputc (*str, file);
+        break;
+    }
+  }
+}
+
 void
 tr_xmlprint (FILE * file, TestResult * tr,
     enum print_output print_mode CK_ATTRIBUTE_UNUSED)
@@ -147,8 +179,12 @@ tr_xmlprint (FILE * file, TestResult * tr,
   fprintf (file, "      <fn>%s:%d</fn>\n", file_name, tr->line);
   fprintf (file, "      <id>%s</id>\n", tr->tname);
   fprintf (file, "      <iteration>%d</iteration>\n", tr->iter);
-  fprintf (file, "      <description>%s</description>\n", tr->tcname);
-  fprintf (file, "      <message>%s</message>\n", tr->msg);
+  fprintf (file, "      <description>");
+  fprint_xml_esc (file, tr->tcname);
+  fprintf (file, "</description>\n");
+  fprintf (file, "      <message>");
+  fprint_xml_esc (file, tr->msg);
+  fprintf (file, "</message>\n");
   fprintf (file, "    </test>\n");
 
   if (slash != NULL) {