Fix attribute parsing to correctly handle white space

This commit is contained in:
Lee Thomason 2012-07-02 10:10:19 -07:00
parent 390e978da1
commit 78a773ddd9
5 changed files with 32 additions and 12 deletions

View File

@ -10,7 +10,7 @@ include(GNUInstallDirs)
################################
# set lib version here
set(GENERIC_LIB_VERSION "1.0.4")
set(GENERIC_LIB_VERSION "1.0.5")
set(GENERIC_LIB_SOVERSION "1")

2
dox
View File

@ -32,7 +32,7 @@ PROJECT_NAME = "TinyXML-2"
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = 1.0.4
PROJECT_NUMBER = 1.0.5
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer

View File

@ -914,13 +914,22 @@ bool XMLUnknown::Accept( XMLVisitor* visitor ) const
// --------- XMLAttribute ---------- //
char* XMLAttribute::ParseDeep( char* p, bool processEntities )
{
p = name.ParseText( p, "=", StrPair::ATTRIBUTE_NAME );
// Parse using the name rules: bug fix, was using ParseText before
p = name.ParseName( p );
if ( !p || !*p ) return 0;
// Skip white space before =
p = XMLUtil::SkipWhiteSpace( p );
if ( !p || *p != '=' ) return 0;
++p; // move up to opening quote
p = XMLUtil::SkipWhiteSpace( p );
if ( *p != '\"' && *p != '\'' ) return 0;
char endTag[2] = { *p, 0 };
++p;
++p; // move past opening quote
p = value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES );
//if ( value.Empty() ) return 0;
return p;
}

View File

@ -85,7 +85,7 @@ distribution.
static const int TIXML2_MAJOR_VERSION = 1;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 4;
static const int TIXML2_PATCH_VERSION = 5;
namespace tinyxml2
{
@ -134,7 +134,7 @@ public:
void SetInternedStr( const char* str ) { Reset(); this->start = const_cast<char*>(str); }
void SetStr( const char* str, int flags=0 );
char* ParseText( char* in, const char* endTag, int strFlags );
char* ParseText( char* in, const char* endTag, int strFlags );
char* ParseName( char* in );

View File

@ -795,12 +795,23 @@ int main( int /*argc*/, const char ** /*argv*/ )
{
// Make sure an attribute with a space in it succeeds.
static const char* xml = "<element attribute1=\"Test Attribute\"/>";
XMLDocument doc;
doc.Parse( xml );
static const char* xml0 = "<element attribute1= \"Test Attribute\"/>";
static const char* xml1 = "<element attribute1 =\"Test Attribute\"/>";
static const char* xml2 = "<element attribute1 = \"Test Attribute\"/>";
XMLDocument doc0;
doc0.Parse( xml0 );
XMLDocument doc1;
doc1.Parse( xml1 );
XMLDocument doc2;
doc2.Parse( xml2 );
XMLElement* ele = doc.FirstChildElement();
XMLTest( "Attribute with space", "Test Attribute", ele->Attribute( "attribute1" ) );
XMLElement* ele = 0;
ele = doc0.FirstChildElement();
XMLTest( "Attribute with space #1", "Test Attribute", ele->Attribute( "attribute1" ) );
ele = doc1.FirstChildElement();
XMLTest( "Attribute with space #2", "Test Attribute", ele->Attribute( "attribute1" ) );
ele = doc2.FirstChildElement();
XMLTest( "Attribute with space #3", "Test Attribute", ele->Attribute( "attribute1" ) );
}
{