From a0f6c9965d22e4d3c28d6bb36899c09fb971fe5f Mon Sep 17 00:00:00 2001 From: Espen Albrektsen Date: Fri, 17 Jul 2015 19:07:19 +0200 Subject: [PATCH] Proposal for fixing #464 - invalid XML in output. --- include/internal/catch_xmlwriter.hpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp index 553c5a79..b3e633ba 100644 --- a/include/internal/catch_xmlwriter.hpp +++ b/include/internal/catch_xmlwriter.hpp @@ -169,9 +169,26 @@ namespace Catch { } } - void writeEncodedText( std::string const& text ) { - static const char* charsToEncode = "<&\""; - std::string mtext = text; + std::string asSafeString( std::string const& text ) { + std::string mtext = text; + std::string safe; + for (int ix=0;ix'\x0D' && c<'\x20') ) { + std::ostringstream stringStream; + stringStream << "?(" << (int)c << ")"; + safe += stringStream.str(); + } + else + safe += c; + } + return safe; + } + + void writeEncodedText( std::string const& text ) { + static const char* charsToEncode = "<&\""; + std::string mtext = asSafeString(text); std::string::size_type pos = mtext.find_first_of( charsToEncode ); while( pos != std::string::npos ) { stream() << mtext.substr( 0, pos );