Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2016-09-22 17:44:14 +0100
committerGitHub2016-09-22 17:44:14 +0100
commitc47c1797d262b6da07884eef490ae84d4319b90f (patch)
tree26a488c76399c6e080756f66d8fddfb15742b1fa /include
parentf5d2b2dce8aa2174d2bab5423a2e9984fe92d07c (diff)
parent5095619955f9f408e503dfcf561923ac6e48e3ce (diff)
downloadcatch3-c47c1797d262b6da07884eef490ae84d4319b90f.tar.gz
Merge pull request #701 from razeh/master
Fixes for XML encoding.
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_xmlwriter.hpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp
index c59725b0..97890d2f 100644
--- a/include/internal/catch_xmlwriter.hpp
+++ b/include/internal/catch_xmlwriter.hpp
@@ -55,9 +55,10 @@ namespace Catch {
break;
default:
- // Escape control chars - based on contribution by @espenalb in PR #465
+ // Escape control chars - based on contribution by @espenalb in PR #465 and
+ // by @mrpi PR #588
if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
- os << "&#x" << std::uppercase << std::hex << static_cast<int>( c );
+ os << "&#x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>( c ) << ';';
else
os << c;
}
@@ -112,13 +113,20 @@ namespace Catch {
: m_tagIsOpen( false ),
m_needsNewline( false ),
m_os( &Catch::cout() )
- {}
+ {
+ // We encode control characters, which requires
+ // XML 1.1
+ // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
+ *m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
+ }
XmlWriter( std::ostream& os )
: m_tagIsOpen( false ),
m_needsNewline( false ),
m_os( &os )
- {}
+ {
+ *m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
+ }
~XmlWriter() {
while( !m_tags.empty() )