XmlWriter reverts to XML 1.0.

Character encodings that are not valid in XML 1.0 are instead written using C-style escapes
This commit is contained in:
Phil Nash
2017-02-06 16:00:05 +00:00
parent f65776890c
commit a189387f49
6 changed files with 121 additions and 52 deletions

View File

@@ -429,9 +429,9 @@ TEST_CASE( "toString on wchar_t returns the string contents", "[toString]" ) {
CHECK( result == "\"wide load\"" );
}
inline std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
inline std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes, Catch::XmlEncode::XmlVersion version = Catch::XmlEncode::_1_0 ) {
std::ostringstream oss;
oss << Catch::XmlEncode( str, forWhat );
oss << Catch::XmlEncode( version, str, forWhat );
return oss.str();
}
@@ -457,11 +457,17 @@ TEST_CASE( "XmlEncode" ) {
REQUIRE( encode( stringWithQuotes ) == stringWithQuotes );
REQUIRE( encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't &quot;quote&quot; me on that" );
}
SECTION( "string with control char (1)" ) {
REQUIRE( encode( "[\x01]" ) == "[&#x01;]" );
SECTION( "string with control char (1) (XML 1.0)" ) {
REQUIRE( encode( "[\x01]" ) == "[\\x01]" );
}
SECTION( "string with control char (x7F)" ) {
REQUIRE( encode( "[\x7F]" ) == "[&#x7F;]" );
SECTION( "string with control char (1) (XMl 1.1)" ) {
REQUIRE( encode( "[\x01]", Catch::XmlEncode::ForTextNodes, Catch::XmlEncode::_1_1 ) == "[&#x01;]" );
}
SECTION( "string with control char (x7F) (XML 1.0)" ) {
REQUIRE( encode( "[\x7F]" ) == "[\\x7F]" );
}
SECTION( "string with control char (x7F) (XML 1.1)" ) {
REQUIRE( encode( "[\x7F]", Catch::XmlEncode::ForTextNodes, Catch::XmlEncode::_1_1 ) == "[&#x7F;]" );
}
}