Commit 259e7c30 authored by Thibault Saunier's avatar Thibault Saunier

libcheck: Escape strings in the generated xml files

This is copy pasted from upstream libcheck
parent 0a41beaa
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment