In PrintString, move the optimization under the if ( _processEntities ) block and retain the strlen Write in the new else block. Added a test case.

This commit is contained in:
Derek Quam
2018-04-18 13:40:46 -05:00
parent 3cdaf8b15e
commit be69ae6352
2 changed files with 20 additions and 7 deletions

View File

@@ -2523,15 +2523,17 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
++q;
TIXMLASSERT( p <= q );
}
}
// Flush the remaining string. This will be the entire
// string if an entity wasn't found.
TIXMLASSERT( p <= q );
if ( !_processEntities || ( p < q ) ) {
if ( p < q ) {
const size_t delta = q - p;
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
Write( p, toPrint );
}
}
else {
Write( p );
}
}

View File

@@ -1995,6 +1995,17 @@ int main( int argc, const char ** argv )
}
}
{
const char* html("<!DOCTYPE html><html><body><p>test</p><p><br/></p></body></html>");
XMLDocument doc(false);
doc.Parse(html);
XMLPrinter printer(0, true);
doc.Print(&printer);
XMLTest(html, html, printer.CStr());
}
{
// Evil memory leaks.
// If an XMLElement (etc) is allocated via NewElement() (etc.)