mirror of https://github.com/AxioDL/tinyxml2.git
Merge branch 'SirR4T-patch-1'
This commit is contained in:
commit
c52aa55a86
13
tinyxml2.cpp
13
tinyxml2.cpp
|
@ -887,6 +887,17 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMLDeclaration* decl = node->ToDeclaration();
|
||||||
|
if ( decl ) {
|
||||||
|
// A declaration can only be the first child of a document.
|
||||||
|
// Set error, if document already has children.
|
||||||
|
if ( !_document->NoChildren() ) {
|
||||||
|
_document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);
|
||||||
|
DeleteNode( decl );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XMLElement* ele = node->ToElement();
|
XMLElement* ele = node->ToElement();
|
||||||
if ( ele ) {
|
if ( ele ) {
|
||||||
// We read the end tag. Return it to the parent.
|
// We read the end tag. Return it to the parent.
|
||||||
|
@ -1846,7 +1857,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
|
||||||
return _errorID;
|
return _errorID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( filelength >= (size_t)-1 ) {
|
if ( (size_t)filelength >= (size_t)-1 ) {
|
||||||
// Cannot handle files which won't fit in buffer together with null terminator
|
// Cannot handle files which won't fit in buffer together with null terminator
|
||||||
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
||||||
return _errorID;
|
return _errorID;
|
||||||
|
|
19
xmltest.cpp
19
xmltest.cpp
|
@ -1460,6 +1460,25 @@ int main( int argc, const char ** argv )
|
||||||
XMLTest( "Error should be cleared", false, doc.Error() );
|
XMLTest( "Error should be cleared", false, doc.Error() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Check that declarations are parsed only as the FirstChild
|
||||||
|
const char* xml0 = "<?xml version=\"1.0\" ?>"
|
||||||
|
" <!-- xml version=\"1.1\" -->"
|
||||||
|
"<first />";
|
||||||
|
const char* xml1 = "<?xml version=\"1.0\" ?>"
|
||||||
|
" <?xml version=\"1.1\" ?>"
|
||||||
|
"<first />";
|
||||||
|
const char* xml2 = "<first />"
|
||||||
|
"<?xml version=\"1.0\" ?>";
|
||||||
|
XMLDocument doc;
|
||||||
|
doc.Parse(xml0);
|
||||||
|
XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false);
|
||||||
|
doc.Parse(xml1);
|
||||||
|
XMLTest("Test that the second declaration throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
|
||||||
|
doc.Parse(xml2);
|
||||||
|
XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------- Performance tracking --------------
|
// ----------- Performance tracking --------------
|
||||||
{
|
{
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
|
|
Loading…
Reference in New Issue