Просмотр исходного кода

Fix attribute parsing to correctly handle white space

Lee Thomason 13 лет назад
Родитель
Сommit
78a773ddd9
5 измененных файлов с 33 добавлено и 13 удалено
  1. 1 1
      CMakeLists.txt
  2. 1 1
      dox
  3. 12 3
      tinyxml2.cpp
  4. 2 2
      tinyxml2.h
  5. 17 6
      xmltest.cpp

+ 1 - 1
CMakeLists.txt

@@ -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")
 
 

+ 1 - 1
dox

@@ -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

+ 12 - 3
tinyxml2.cpp

@@ -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;
 }
 

+ 2 - 2
tinyxml2.h

@@ -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 );
 
 

+ 17 - 6
xmltest.cpp

@@ -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 );
-
-		XMLElement* ele = doc.FirstChildElement();
-		XMLTest( "Attribute with space", "Test Attribute", ele->Attribute( "attribute1" ) );
+		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 = 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" ) );
 	}
 
 	{