From 259e7c30a06fbe0777ba47183ed27b87abe0224d Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 23 Jul 2013 15:39:53 -0400 Subject: [PATCH] libcheck: Escape strings in the generated xml files This is copy pasted from upstream libcheck --- libs/gst/check/libcheck/check_print.c | 40 +++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/libs/gst/check/libcheck/check_print.c b/libs/gst/check/libcheck/check_print.c index f170d60ee6..e29aa7b0f1 100644 --- a/libs/gst/check/libcheck/check_print.c +++ b/libs/gst/check/libcheck/check_print.c @@ -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 ("<", file); + break; + case '>': + fputs (">", file); + break; + case '&': + fputs ("&", 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, " %s:%d\n", file_name, tr->line); fprintf (file, " %s\n", tr->tname); fprintf (file, " %d\n", tr->iter); - fprintf (file, " %s\n", tr->tcname); - fprintf (file, " %s\n", tr->msg); + fprintf (file, " "); + fprint_xml_esc (file, tr->tcname); + fprintf (file, "\n"); + fprintf (file, " "); + fprint_xml_esc (file, tr->msg); + fprintf (file, "\n"); fprintf (file, " \n"); if (slash != NULL) {