improved parser handling of pathologic attributes

This commit is contained in:
rickg%netscape.com 1998-07-29 05:13:35 +00:00
Родитель 7227de9f21
Коммит 3268db96ab
6 изменённых файлов: 114 добавлений и 32 удалений

Просмотреть файл

@ -832,6 +832,7 @@ PRInt32 ConsumeAttributeValueText(PRUnichar,nsString& aString,CScanner& aScanner
nsresult CAttributeToken::Consume(PRUnichar aChar, CScanner& aScanner) {
aScanner.SkipWhitespace(); //skip leading whitespace
static nsAutoString kAllButEqualOrGT("=>");
nsresult result=aScanner.Peek(aChar);
if(NS_OK==result) {
if(kQuote==aChar) { //if you're here, handle quoted key...
@ -857,25 +858,28 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, CScanner& aScanner) {
//now it's time to Consume the (optional) value...
if(NS_OK == (result=aScanner.SkipWhitespace())) {
if(NS_OK == (result=aScanner.Peek(aChar))) {
if(kEqual==aChar){
result=aScanner.GetChar(aChar); //skip the equal sign...
if(NS_OK==result) {
result=aScanner.SkipWhitespace(); //now skip any intervening whitespace
//Skip ahead until you find an equal sign or a '>'...
if(NS_OK == (result=aScanner.SkipTo(kAllButEqualOrGT))) {
if(NS_OK == (result=aScanner.Peek(aChar))) {
if(kEqual==aChar){
result=aScanner.GetChar(aChar); //skip the equal sign...
if(NS_OK==result) {
result=aScanner.GetChar(aChar); //and grab the next char.
result=aScanner.SkipWhitespace(); //now skip any intervening whitespace
if(NS_OK==result) {
if((kQuote==aChar) || (kApostrophe==aChar)) {
mTextValue=aChar;
result=ConsumeQuotedString(aChar,mTextValue,aScanner);
}
else {
mTextValue=aChar; //it's an alphanum attribute...
result=ConsumeAttributeValueText(aChar,mTextValue,aScanner);
}
result=aScanner.GetChar(aChar); //and grab the next char.
if(NS_OK==result) {
if((kQuote==aChar) || (kApostrophe==aChar)) {
mTextValue=aChar;
result=ConsumeQuotedString(aChar,mTextValue,aScanner);
}
else {
mTextValue=aChar; //it's an alphanum attribute...
result=ConsumeAttributeValueText(aChar,mTextValue,aScanner);
}
}//if
if(NS_OK==result)
result=aScanner.SkipWhitespace();
}//if
if(NS_OK==result)
result=aScanner.SkipWhitespace();
}//if
}//if
}//if

Просмотреть файл

@ -351,6 +351,34 @@ nsresult CScanner::SkipOver(nsString& aSkipSet){
return result;
}
/**
* Skip over chars until they're in aValidSet
*
* @update gess 3/25/98
* @param aValid set contains chars you're looking for
* @return error code
*/
nsresult CScanner::SkipTo(nsString& aValidSet){
PRUnichar ch=0;
nsresult result=NS_OK;
while(NS_OK==result) {
result=GetChar(ch);
if(NS_OK == result) {
PRInt32 pos=aValidSet.Find(ch);
if(kNotFound!=pos) {
PutBack(ch);
break;
}
}
else break;
} //while
return result;
}
/**
* Skip over chars as long as they're in aValidSet
*

Просмотреть файл

@ -120,6 +120,15 @@ class CScanner {
*/
nsresult SkipOver(PRUnichar aSkipChar);
/**
* Skip over chars until they're in aValidSet
*
* @update gess 3/25/98
* @param aValid set contains chars you're looking for
* @return error code
*/
nsresult SkipTo(nsString& aValidSet);
/**
* Skip over chars as long as they're in aSequence
*

Просмотреть файл

@ -832,6 +832,7 @@ PRInt32 ConsumeAttributeValueText(PRUnichar,nsString& aString,CScanner& aScanner
nsresult CAttributeToken::Consume(PRUnichar aChar, CScanner& aScanner) {
aScanner.SkipWhitespace(); //skip leading whitespace
static nsAutoString kAllButEqualOrGT("=>");
nsresult result=aScanner.Peek(aChar);
if(NS_OK==result) {
if(kQuote==aChar) { //if you're here, handle quoted key...
@ -857,25 +858,28 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, CScanner& aScanner) {
//now it's time to Consume the (optional) value...
if(NS_OK == (result=aScanner.SkipWhitespace())) {
if(NS_OK == (result=aScanner.Peek(aChar))) {
if(kEqual==aChar){
result=aScanner.GetChar(aChar); //skip the equal sign...
if(NS_OK==result) {
result=aScanner.SkipWhitespace(); //now skip any intervening whitespace
//Skip ahead until you find an equal sign or a '>'...
if(NS_OK == (result=aScanner.SkipTo(kAllButEqualOrGT))) {
if(NS_OK == (result=aScanner.Peek(aChar))) {
if(kEqual==aChar){
result=aScanner.GetChar(aChar); //skip the equal sign...
if(NS_OK==result) {
result=aScanner.GetChar(aChar); //and grab the next char.
result=aScanner.SkipWhitespace(); //now skip any intervening whitespace
if(NS_OK==result) {
if((kQuote==aChar) || (kApostrophe==aChar)) {
mTextValue=aChar;
result=ConsumeQuotedString(aChar,mTextValue,aScanner);
}
else {
mTextValue=aChar; //it's an alphanum attribute...
result=ConsumeAttributeValueText(aChar,mTextValue,aScanner);
}
result=aScanner.GetChar(aChar); //and grab the next char.
if(NS_OK==result) {
if((kQuote==aChar) || (kApostrophe==aChar)) {
mTextValue=aChar;
result=ConsumeQuotedString(aChar,mTextValue,aScanner);
}
else {
mTextValue=aChar; //it's an alphanum attribute...
result=ConsumeAttributeValueText(aChar,mTextValue,aScanner);
}
}//if
if(NS_OK==result)
result=aScanner.SkipWhitespace();
}//if
if(NS_OK==result)
result=aScanner.SkipWhitespace();
}//if
}//if
}//if

Просмотреть файл

@ -351,6 +351,34 @@ nsresult CScanner::SkipOver(nsString& aSkipSet){
return result;
}
/**
* Skip over chars until they're in aValidSet
*
* @update gess 3/25/98
* @param aValid set contains chars you're looking for
* @return error code
*/
nsresult CScanner::SkipTo(nsString& aValidSet){
PRUnichar ch=0;
nsresult result=NS_OK;
while(NS_OK==result) {
result=GetChar(ch);
if(NS_OK == result) {
PRInt32 pos=aValidSet.Find(ch);
if(kNotFound!=pos) {
PutBack(ch);
break;
}
}
else break;
} //while
return result;
}
/**
* Skip over chars as long as they're in aValidSet
*

Просмотреть файл

@ -120,6 +120,15 @@ class CScanner {
*/
nsresult SkipOver(PRUnichar aSkipChar);
/**
* Skip over chars until they're in aValidSet
*
* @update gess 3/25/98
* @param aValid set contains chars you're looking for
* @return error code
*/
nsresult SkipTo(nsString& aValidSet);
/**
* Skip over chars as long as they're in aSequence
*