diff --git a/NEWS b/NEWS index 9f793373..197f40a4 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,11 @@ STILL UNDER DEVELOPMENT; NOT RELEASED YET. executing a test program. This should help crossbuild systems by providing a mechanism to pre-specify what the results should be. +* PR bin/45690: Make atf-report convert any non-printable characters to + a plain-text representation (matching their corresponding hexadecimal + entities) in XML output files. This is to prevent the output of test + cases from breaking xsltproc later. + Changes in version 0.16 *********************** diff --git a/atf-report/atf-report.cpp b/atf-report/atf-report.cpp index bcc70408..359b58b2 100644 --- a/atf-report/atf-report.cpp +++ b/atf-report/atf-report.cpp @@ -31,6 +31,7 @@ extern "C" { #include } +#include #include #include #include @@ -394,17 +395,24 @@ class xml_writer : public writer { std::string elemval(const std::string& str) { - std::string ostr; + std::ostringstream buf; for (std::string::const_iterator iter = str.begin(); iter != str.end(); iter++) { - switch (*iter) { - case '&': ostr += "&"; break; - case '<': ostr += "<"; break; - case '>': ostr += ">"; break; - default: ostr += *iter; + const int character = static_cast< unsigned char >(*iter); + if (character == '&') { + buf << "&"; + } else if (character == '<') { + buf << "<"; + } else if (character == '>') { + buf << ">"; + } else if (std::isalnum(character) || std::ispunct(character) || + std::isspace(character)) { + buf << static_cast< char >(character); + } else { + buf << "&#" << character << ";"; } } - return ostr; + return buf.str(); } void