mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Fix for bug# 7548.
Added a Sanitize() method for attribute tokens that would remove non-alpha-non-digit characters from the end of a string ( could be a "key" or "value")
This commit is contained in:
parent
5790273c8d
commit
7163a4d801
@ -1691,6 +1691,13 @@ nsresult CNavDTD::CollectAttributes(nsCParserNode& aNode,eHTMLTags aTag,PRInt32
|
||||
theToken=(CToken*)mSkippedContent.PopFront();
|
||||
else theToken=mTokenizer->PopToken();
|
||||
if(theToken) {
|
||||
CAttributeToken* theAttrToken = ((CAttributeToken*)theToken);
|
||||
nsString& key=theAttrToken->GetKey();
|
||||
// Sanitize the key for it might contain some non-alpha-non-digit characters
|
||||
// at its end. Ex. <OPTION SELECTED/> - This will be tokenized as "<" "OPTION",
|
||||
// "SELECTED/", and ">". In this case the "SELECTED/" key will be sanitized to
|
||||
// a legitimate "SELECTED" key.
|
||||
theAttrToken->Sanitize(key);
|
||||
|
||||
#ifdef RICKG_DEBUG
|
||||
WriteTokenToLog(theToken);
|
||||
|
@ -1046,6 +1046,27 @@ PRInt32 CAttributeToken::GetTokenType(void) {
|
||||
return eToken_attribute;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes non-alpha-non-digit characters from the end of the string
|
||||
*
|
||||
* @update harishd 07/15/99
|
||||
* @param aString - The string might contain garbage at the end!!
|
||||
* @return
|
||||
*/
|
||||
void CAttributeToken::Sanitize(nsString& aString) {
|
||||
PRInt32 length=aString.Length();
|
||||
if(length > 0) {
|
||||
PRUnichar theChar=aString.Last();
|
||||
while(!nsString::IsAlpha(theChar) && !nsString::IsDigit(theChar)) {
|
||||
aString.Truncate(length-1);
|
||||
length = aString.Length();
|
||||
if(length <= 0) break;
|
||||
theChar = aString.Last();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump contents of this token to given output stream
|
||||
*
|
||||
|
@ -262,6 +262,7 @@ class CAttributeToken: public CHTMLToken {
|
||||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
virtual nsString& GetKey(void) {return mTextKey;}
|
||||
virtual void Sanitize(nsString& aString);
|
||||
virtual void DebugDumpToken(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
|
@ -1691,6 +1691,13 @@ nsresult CNavDTD::CollectAttributes(nsCParserNode& aNode,eHTMLTags aTag,PRInt32
|
||||
theToken=(CToken*)mSkippedContent.PopFront();
|
||||
else theToken=mTokenizer->PopToken();
|
||||
if(theToken) {
|
||||
CAttributeToken* theAttrToken = ((CAttributeToken*)theToken);
|
||||
nsString& key=theAttrToken->GetKey();
|
||||
// Sanitize the key for it might contain some non-alpha-non-digit characters
|
||||
// at its end. Ex. <OPTION SELECTED/> - This will be tokenized as "<" "OPTION",
|
||||
// "SELECTED/", and ">". In this case the "SELECTED/" key will be sanitized to
|
||||
// a legitimate "SELECTED" key.
|
||||
theAttrToken->Sanitize(key);
|
||||
|
||||
#ifdef RICKG_DEBUG
|
||||
WriteTokenToLog(theToken);
|
||||
|
@ -1046,6 +1046,27 @@ PRInt32 CAttributeToken::GetTokenType(void) {
|
||||
return eToken_attribute;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes non-alpha-non-digit characters from the end of the string
|
||||
*
|
||||
* @update harishd 07/15/99
|
||||
* @param aString - The string might contain garbage at the end!!
|
||||
* @return
|
||||
*/
|
||||
void CAttributeToken::Sanitize(nsString& aString) {
|
||||
PRInt32 length=aString.Length();
|
||||
if(length > 0) {
|
||||
PRUnichar theChar=aString.Last();
|
||||
while(!nsString::IsAlpha(theChar) && !nsString::IsDigit(theChar)) {
|
||||
aString.Truncate(length-1);
|
||||
length = aString.Length();
|
||||
if(length <= 0) break;
|
||||
theChar = aString.Last();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump contents of this token to given output stream
|
||||
*
|
||||
|
@ -262,6 +262,7 @@ class CAttributeToken: public CHTMLToken {
|
||||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
virtual nsString& GetKey(void) {return mTextKey;}
|
||||
virtual void Sanitize(nsString& aString);
|
||||
virtual void DebugDumpToken(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
|
Loading…
Reference in New Issue
Block a user