Skip to content

Commit

Permalink
Do not write unprintable characters in XML reports
Browse files Browse the repository at this point in the history
Convert some unprintable characters to a *plain-text* representation in
XML reports.  This is a little hack but does the trick for now.

The NetBSD test suite has started spitting out a character with value 27,
and that confuses xsltproc when processing an XML-based report created by
atf-report.  Even converting the character to  doesn't seem to work.
  • Loading branch information
jmmv committed Feb 14, 2013
1 parent 1d5ba64 commit 03559ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
***********************
Expand Down
22 changes: 15 additions & 7 deletions atf-report/atf-report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
#include <sys/time.h>
}

#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
Expand Down Expand Up @@ -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 += "&amp;"; break;
case '<': ostr += "&lt;"; break;
case '>': ostr += "&gt;"; break;
default: ostr += *iter;
const int character = static_cast< unsigned char >(*iter);
if (character == '&') {
buf << "&amp;";
} else if (character == '<') {
buf << "&lt;";
} else if (character == '>') {
buf << "&gt;";
} else if (std::isalnum(character) || std::ispunct(character) ||
std::isspace(character)) {
buf << static_cast< char >(character);
} else {
buf << "&amp;#" << character << ";";
}
}
return ostr;
return buf.str();
}

void
Expand Down

0 comments on commit 03559ce

Please sign in to comment.