mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Fixed GitHub Issue #70
Interleave XML entities are now encoded correctly
This commit is contained in:
parent
a162e22fa3
commit
0b09d1c089
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ Release
|
|||||||
*.xcuserstate
|
*.xcuserstate
|
||||||
.DS_Store
|
.DS_Store
|
||||||
xcuserdata
|
xcuserdata
|
||||||
|
CatchSelfTest.xcscheme
|
@ -294,31 +294,29 @@ namespace Catch
|
|||||||
const std::string& text
|
const std::string& text
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// !TBD finish this
|
static const char* charsToEncode = "<&\"";
|
||||||
if( !findReplaceableString( text, "<", "<" ) &&
|
std::string mtext = text;
|
||||||
!findReplaceableString( text, "&", "&" ) &&
|
std::string::size_type pos = mtext.find_first_of( charsToEncode );
|
||||||
!findReplaceableString( text, "\"", """ ) )
|
while( pos != std::string::npos )
|
||||||
{
|
{
|
||||||
stream() << text;
|
stream() << mtext.substr( 0, pos );
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
switch( mtext[pos] )
|
||||||
bool findReplaceableString
|
{
|
||||||
(
|
case '<':
|
||||||
const std::string& text,
|
stream() << "<";
|
||||||
const std::string& replaceWhat,
|
break;
|
||||||
const std::string& replaceWith
|
case '&':
|
||||||
)
|
stream() << "&";
|
||||||
{
|
break;
|
||||||
std::string::size_type pos = text.find_first_of( replaceWhat );
|
case '\"':
|
||||||
if( pos != std::string::npos )
|
stream() << """;
|
||||||
{
|
break;
|
||||||
stream() << text.substr( 0, pos ) << replaceWith;
|
}
|
||||||
writeEncodedText( text.substr( pos+1 ) );
|
mtext = mtext.substr( pos+1 );
|
||||||
return true;
|
pos = mtext.find_first_of( charsToEncode );
|
||||||
}
|
}
|
||||||
return false;
|
stream() << mtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool m_tagIsOpen;
|
bool m_tagIsOpen;
|
||||||
|
@ -157,3 +157,15 @@ TEST_CASE( "./failing/checkedelse", "" )
|
|||||||
{
|
{
|
||||||
REQUIRE( testCheckedElse( false ) );
|
REQUIRE( testCheckedElse( false ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "./misc/xmlentitycheck", "" )
|
||||||
|
{
|
||||||
|
SECTION( "embedded xml", "<test>it should be possible to embed xml characters, such as <, \" or &, or even whole <xml>documents</xml> within an attribute</test>" )
|
||||||
|
{
|
||||||
|
// No test
|
||||||
|
}
|
||||||
|
SECTION( "encoded chars", "these should all be encoded: &&&\"\"\"<<<&\"<<&\"" )
|
||||||
|
{
|
||||||
|
// No test
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user