mirror of https://github.com/AxioDL/tinyxml2.git
Merge remote-tracking branch 'martinsh/issue#53-fix'
This commit is contained in:
commit
0aecb5c770
|
@ -136,12 +136,7 @@ char* StrPair::ParseName( char* p )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( *p && (
|
while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) {
|
||||||
XMLUtil::IsAlphaNum( (unsigned char) *p )
|
|
||||||
|| *p == '_'
|
|
||||||
|| *p == ':'
|
|
||||||
|| (*p == '-' && p>start ) // can be in a name, but not lead it.
|
|
||||||
|| (*p == '.' && p>start ) )) { // can be in a name, but not lead it.
|
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1357,7 +1352,7 @@ char* XMLElement::ParseAttributes( char* p )
|
||||||
}
|
}
|
||||||
|
|
||||||
// attribute.
|
// attribute.
|
||||||
if ( XMLUtil::IsAlpha( *p ) ) {
|
if (XMLUtil::IsNameStartChar( *p ) ) {
|
||||||
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
||||||
attrib->_memPool = &_document->_attributePool;
|
attrib->_memPool = &_document->_attributePool;
|
||||||
attrib->_memPool->SetTracked();
|
attrib->_memPool->SetTracked();
|
||||||
|
|
20
tinyxml2.h
20
tinyxml2.h
|
@ -465,6 +465,19 @@ public:
|
||||||
return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
|
return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static bool IsNameStartChar( unsigned char ch ) {
|
||||||
|
return ( ( ch < 128 ) ? isalpha( ch ) : 1 )
|
||||||
|
|| ch == ':'
|
||||||
|
|| ch == '_';
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static bool IsNameChar( unsigned char ch ) {
|
||||||
|
return IsNameStartChar( ch )
|
||||||
|
|| isdigit( ch )
|
||||||
|
|| ch == '.'
|
||||||
|
|| ch == '-';
|
||||||
|
}
|
||||||
|
|
||||||
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
|
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
if ( p == q ) {
|
if ( p == q ) {
|
||||||
|
@ -480,15 +493,10 @@ public:
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static int IsUTF8Continuation( const char p ) {
|
inline static int IsUTF8Continuation( const char p ) {
|
||||||
return p & 0x80;
|
return p & 0x80;
|
||||||
}
|
}
|
||||||
inline static int IsAlphaNum( unsigned char anyByte ) {
|
|
||||||
return ( anyByte < 128 ) ? isalnum( anyByte ) : 1;
|
|
||||||
}
|
|
||||||
inline static int IsAlpha( unsigned char anyByte ) {
|
|
||||||
return ( anyByte < 128 ) ? isalpha( anyByte ) : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* ReadBOM( const char* p, bool* hasBOM );
|
static const char* ReadBOM( const char* p, bool* hasBOM );
|
||||||
// p is the starting location,
|
// p is the starting location,
|
||||||
|
|
14
xmltest.cpp
14
xmltest.cpp
|
@ -1051,6 +1051,20 @@ int main( int argc, const char ** argv )
|
||||||
XMLTest( "Non-alpha element lead letter parses.", doc.Error(), false );
|
XMLTest( "Non-alpha element lead letter parses.", doc.Error(), false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char* xml = "<element _attr1=\"foo\" :attr2=\"bar\"></element>";
|
||||||
|
XMLDocument doc;
|
||||||
|
doc.Parse( xml );
|
||||||
|
XMLTest("Non-alpha attribute lead character parses.", doc.Error(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char* xml = "<3lement></3lement>";
|
||||||
|
XMLDocument doc;
|
||||||
|
doc.Parse( xml );
|
||||||
|
XMLTest("Element names with lead digit fail to parse.", doc.Error(), true);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char* xml = "<element/>WOA THIS ISN'T GOING TO PARSE";
|
const char* xml = "<element/>WOA THIS ISN'T GOING TO PARSE";
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
|
|
Loading…
Reference in New Issue