mirror of
https://github.com/catchorg/Catch2.git
synced 2025-02-22 06:03:31 +01:00
1. fixed bug in XmlEncode::encodeTo(): incorrect escaping of UTF-8 symbols
2. added test for XmlEncode in case of UTF-8 symbols
This commit is contained in:
parent
c984fc3ecd
commit
42d4e9f1b0
@ -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<int>( c );
|
||||
os << "&#x" << std::uppercase << std::hex << static_cast<int>( c ) << ";";
|
||||
else
|
||||
os << c;
|
||||
}
|
||||
|
@ -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( "ðóññêèé òåêñò" ) == "ðóññêèé òåêñò" );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user