libcheck: Escape strings in the generated xml files

This is copy pasted from upstream libcheck
This commit is contained in:
Thibault Saunier 2013-07-23 15:39:53 -04:00
parent 0a41beaa56
commit 259e7c30a0

View 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 (""", file);
break;
case '\'':
fputs ("'", 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) {