From 42d4e9f1b05d91ccf53cbc097171d6555b851921 Mon Sep 17 00:00:00 2001 From: Vladimir Zelyonkin Date: Tue, 5 Apr 2016 10:00:15 +0300 Subject: [PATCH] 1. fixed bug in XmlEncode::encodeTo(): incorrect escaping of UTF-8 symbols 2. added test for XmlEncode in case of UTF-8 symbols --- include/internal/catch_xmlwriter.hpp | 4 ++-- projects/SelfTest/MiscTests.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp index c59725b0..cdff5a2e 100644 --- a/include/internal/catch_xmlwriter.hpp +++ b/include/internal/catch_xmlwriter.hpp @@ -34,7 +34,7 @@ namespace Catch { // (see: http://www.w3.org/TR/xml/#syntax) for( std::size_t i = 0; i < m_str.size(); ++ i ) { - char c = m_str[i]; + unsigned char c = m_str[i]; switch( c ) { case '<': os << "<"; break; case '&': os << "&"; break; @@ -57,7 +57,7 @@ namespace Catch { default: // Escape control chars - based on contribution by @espenalb in PR #465 if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) - os << "&#x" << std::uppercase << std::hex << static_cast( c ); + os << "&#x" << std::uppercase << std::hex << static_cast( c ) << ";"; else os << c; } diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index 9a2a2ab6..eb241465 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -458,10 +458,13 @@ TEST_CASE( "XmlEncode" ) { REQUIRE( encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't "quote" me on that" ); } SECTION( "string with control char (1)" ) { - REQUIRE( encode( "[\x01]" ) == "[]" ); + REQUIRE( encode( "[\x01]" ) == "[]" ); } SECTION( "string with control char (x7F)" ) { - REQUIRE( encode( "[\x7F]" ) == "[]" ); + REQUIRE( encode( "[\x7F]" ) == "[]" ); + } + SECTION( "string with utf-8 characters (русский текст)" ) { + REQUIRE( encode( "русский текст" ) == "русский текст" ); } }