diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index c6edcd316b4..d5f105b461a 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -71,13 +71,6 @@ static char* kVerificationDir = "c:/temp"; static char gShowCRC; #endif -static eHTMLTags gFormElementTags[]= { - eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input, - eHTMLTag_isindex, eHTMLTag_label, eHTMLTag_legend, - eHTMLTag_option, eHTMLTag_optgroup, eHTMLTag_select, - eHTMLTag_textarea}; - - #include "nsElementTable.h" @@ -519,7 +512,7 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke if(!mBodyContext->GetCount()) { //if the content model is empty, then begin by opening ... - CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_html); + CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_html,"html"); HandleStartToken(theToken); //this token should get pushed on the context stack, don't recycle it. } @@ -556,7 +549,7 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse if((NS_OK==anErrorCode) && (!mHadBody) && (!mHadFrameset)) { - CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body); + CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body,"body"); mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content result=BuildModel(aParser,mTokenizer,0,aSink); @@ -635,7 +628,7 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse * What's wrong with it? This table, and the dispatch methods themselves need to be * moved over to the delegate. Ah, so much to do... * - * @update gess 5/21/98 + * @update gess 12/1/99 * @param aToken * @param aParser * @return @@ -706,7 +699,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ if(gHTMLElements[eHTMLTag_body].SectionContains(theTag,PR_TRUE)){ mTokenizer->PushTokenFront(aToken); //put this token back... mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content - theToken=(CHTMLToken*)mTokenRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body); + theToken=(CHTMLToken*)mTokenRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body,"body"); theType=eToken_start; //now open a body... } @@ -735,20 +728,29 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ case eToken_whitespace: case eToken_newline: result=HandleStartToken(theToken); break; + case eToken_end: result=HandleEndToken(theToken); break; + + case eToken_cdatasection: case eToken_comment: result=HandleCommentToken(theToken); break; + case eToken_entity: result=HandleEntityToken(theToken); break; + case eToken_attribute: result=HandleAttributeToken(theToken); break; + case eToken_style: result=HandleStyleToken(theToken); break; + case eToken_instruction: result=HandleProcessingInstructionToken(theToken); break; + case eToken_doctypeDecl: result=HandleDocTypeDeclToken(theToken); break; + default: break; }//switch @@ -1244,7 +1246,6 @@ nsresult CNavDTD::HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags nsresult CNavDTD::HandleStartToken(CToken* aToken) { NS_PRECONDITION(0!=aToken,kNullToken); - #ifdef RICKG_DEBUG WriteTokenToLog(aToken); #endif @@ -1253,7 +1254,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { nsCParserNode* theNode=CreateNode(); theNode->Init(aToken,mLineNumber,mTokenRecycler); - + eHTMLTags theChildTag=(eHTMLTags)aToken->GetTypeID(); PRInt16 attrCount=aToken->GetAttributeCount(); eHTMLTags theParent=mBodyContext->Last(); diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index 8a49847de9c..cd656990ee3 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -337,7 +337,7 @@ NS_IMETHODIMP COtherDTD::ConvertEntityToUnicode(const nsString& aEntity, PRInt32 * @param aTag -- tag to test for containership * @return PR_TRUE if given tag can contain other tags */ -PRBool COtherDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRInt32 aParentContains) const { +PRBool COtherDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRBool& aParentContains) const { return CNavDTD::CanOmit(aParent,aChild,aParentContains); } diff --git a/mozilla/htmlparser/src/COtherDTD.h b/mozilla/htmlparser/src/COtherDTD.h index 547946211b0..fd1bc877f7c 100644 --- a/mozilla/htmlparser/src/COtherDTD.h +++ b/mozilla/htmlparser/src/COtherDTD.h @@ -123,7 +123,7 @@ class COtherDTD : public CNavDTD { * @param aTag -- tag to test for containership * @return PR_TRUE if given tag can contain other tags */ - virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRInt32 aParentContains)const; + virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRBool& aParentContains) const; /** * Give rest of world access to our tag enums, so that CanContain(), etc, diff --git a/mozilla/htmlparser/src/nsElementTable.cpp b/mozilla/htmlparser/src/nsElementTable.cpp index c0730053b4d..526e45e652e 100644 --- a/mozilla/htmlparser/src/nsElementTable.cpp +++ b/mozilla/htmlparser/src/nsElementTable.cpp @@ -956,7 +956,7 @@ void InitializeElementTable(void) { Initialize( /*tag*/ eHTMLTag_p, /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, - /*rootnodes,endrootnodes*/ &gInBody,&gInBody, + /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,&gDontAutoClose, /*parent,incl,exclgroups*/ kBlock, kInlineEntity, kNone, //this used to contain FLOW. But it's really an inline container. /*special props, prop-range*/ 0,kDefaultPropRange, //otherwise it tries to contain things like H1..H6 diff --git a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp index 590aeb0ef3d..98fdcc68f04 100644 --- a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp @@ -322,7 +322,7 @@ nsresult nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner) { break; } //switch - return NS_OK; + return result; } @@ -692,8 +692,11 @@ nsresult nsHTMLTokenizer::ConsumeSpecialMarkup(PRUnichar aChar,CToken*& aToken,n PRInt32 theIndex=theBufCopy.Find("DOCTYPE"); CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - if(theIndex==kNotFound) - aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment); + if(theIndex==kNotFound) { + if('['==theBufCopy.CharAt(0)) + aToken = theRecycler->CreateTokenOfType(eToken_cdatasection,eHTMLTag_comment); + else aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment); + } else aToken = theRecycler->CreateTokenOfType(eToken_doctypeDecl,eHTMLTag_markupDecl); diff --git a/mozilla/htmlparser/src/nsHTMLTokens.cpp b/mozilla/htmlparser/src/nsHTMLTokens.cpp index 17aabee8a7f..88dccf4c3a8 100644 --- a/mozilla/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokens.cpp @@ -1935,39 +1935,19 @@ const nsParserError * CErrorToken::GetError(void) CDoctypeDeclToken::CDoctypeDeclToken(eHTMLTags aTag) : CHTMLToken(aTag) { } +/** + * This method consumes a doctype element. + * Note: I'm rewriting this method to seek to the first <, since quotes can really screw us up. + * + * @update gess 9/23/98 + * @param + * @return + */ nsresult CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aMode) { - nsresult result=NS_OK; mTextValue="["; - PRBool done=PR_FALSE; - - result=aScanner.ReadUntil(mTextValue,theTerminals,PR_TRUE,PR_FALSE); - - while(!done && NS_OK==result){ - result=aScanner.Peek(aChar); - if(result==NS_OK) { - if(kQuote==aChar) { - result=aScanner.GetChar(aChar); - if(NS_OK==result) mTextValue += aChar; // append the quote that you just got - result=aScanner.ReadUntil(mTextValue,kQuote,PR_TRUE); - if(NS_OK==result && aMode!=eParseMode_noquirks) - result=aScanner.ReadWhile(mTextValue,"\"",PR_TRUE,PR_FALSE); // consume multiple quotes - } - else if(kLeftSquareBracket==aChar) { - result=aScanner.ReadUntil(mTextValue,kRightSquareBracket,PR_TRUE); - } - else if(kGreaterThan==aChar){ - result=aScanner.ReadUntil(mTextValue,kGreaterThan,PR_TRUE); - done=PR_TRUE; - } - else { - result=aScanner.GetChar(aChar); - if(result==NS_OK) mTextValue += aChar; - } - } - } + nsresult result=aScanner.ReadUntil(mTextValue,'<',PR_FALSE); return result; } diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index 9f02e7ba47a..2c1110a8da2 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -798,6 +798,12 @@ nsresult nsParser::Parse(const nsString& aSourceBuffer,void* aKey,const nsString //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! + +#if 0 + //this is only for debug purposes + aSourceBuffer.DebugDump(); +#endif + nsresult result=NS_OK; nsParser* me = this; // Maintain a reference to ourselves so we don't go away diff --git a/mozilla/htmlparser/src/nsScanner.cpp b/mozilla/htmlparser/src/nsScanner.cpp index b22dd8c5839..1f26168aa14 100644 --- a/mozilla/htmlparser/src/nsScanner.cpp +++ b/mozilla/htmlparser/src/nsScanner.cpp @@ -608,6 +608,7 @@ nsresult nsScanner::SkipPast(nsString& aValidSet){ return NS_OK; } + /** * Consume characters until you find the terminal char * @@ -652,7 +653,8 @@ nsresult nsScanner::ReadIdentifier(nsString& aString) { } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -698,7 +700,8 @@ nsresult nsScanner::ReadNumber(nsString& aString) { } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -747,7 +750,8 @@ nsresult nsScanner::ReadWhitespace(nsString& aString) { } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -794,7 +798,8 @@ nsresult nsScanner::ReadWhile(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -842,7 +847,8 @@ nsresult nsScanner::ReadWhile(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -921,7 +927,8 @@ nsresult nsScanner::ReadUntil(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -970,7 +977,8 @@ nsresult nsScanner::ReadUntil(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -1042,7 +1050,8 @@ nsresult nsScanner::ReadUntil(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],theLen-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],theLen-theOrigin); mOffset=theLen; result=Peek(theChar); theLen=mBuffer.Length(); diff --git a/mozilla/htmlparser/src/nsScanner.h b/mozilla/htmlparser/src/nsScanner.h index 813da1ee0f4..57a499f9604 100644 --- a/mozilla/htmlparser/src/nsScanner.h +++ b/mozilla/htmlparser/src/nsScanner.h @@ -316,6 +316,7 @@ class nsScanner { protected: + enum {eBufferSizeThreshold=0x1000}; //4K /** diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/htmlparser/src/nsViewSourceHTML.cpp index 16a9f3c2063..45f4826c06d 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/htmlparser/src/nsViewSourceHTML.cpp @@ -208,7 +208,7 @@ public: CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mStartTag("start"), mEndTag("end"), mCommentTag("comment"), mDocTypeTag("doctype"), mPITag("pi"), mEntityTag("entity"), - mText("txt"), mKey("key"), mValue("val") + mText("txt"), mKey("key"), mValue("val"), mCDATATag("cdata") { NS_INIT_REFCNT(); mParser=0; @@ -877,6 +877,15 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { result=WriteTag(mEndTag,aToken,0,PR_TRUE); break; + case eToken_cdatasection: + { + nsString& theStr=aToken->GetStringValueXXX(); + theStr.Insert(""); + result=WriteTag(mCDATATag,aToken,0,PR_TRUE); + } + break; + case eToken_comment: result=WriteTag(mCommentTag,aToken,0,PR_TRUE); break; diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.h b/mozilla/htmlparser/src/nsViewSourceHTML.h index ead2d604a71..1bd26fd9939 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/htmlparser/src/nsViewSourceHTML.h @@ -273,6 +273,7 @@ protected: nsAutoString mStartTag; nsAutoString mEndTag; nsAutoString mCommentTag; + nsAutoString mCDATATag; nsAutoString mDocTypeTag; nsAutoString mPITag; nsAutoString mEntityTag; diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index c6edcd316b4..d5f105b461a 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -71,13 +71,6 @@ static char* kVerificationDir = "c:/temp"; static char gShowCRC; #endif -static eHTMLTags gFormElementTags[]= { - eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input, - eHTMLTag_isindex, eHTMLTag_label, eHTMLTag_legend, - eHTMLTag_option, eHTMLTag_optgroup, eHTMLTag_select, - eHTMLTag_textarea}; - - #include "nsElementTable.h" @@ -519,7 +512,7 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke if(!mBodyContext->GetCount()) { //if the content model is empty, then begin by opening ... - CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_html); + CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_html,"html"); HandleStartToken(theToken); //this token should get pushed on the context stack, don't recycle it. } @@ -556,7 +549,7 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse if((NS_OK==anErrorCode) && (!mHadBody) && (!mHadFrameset)) { - CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body); + CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body,"body"); mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content result=BuildModel(aParser,mTokenizer,0,aSink); @@ -635,7 +628,7 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse * What's wrong with it? This table, and the dispatch methods themselves need to be * moved over to the delegate. Ah, so much to do... * - * @update gess 5/21/98 + * @update gess 12/1/99 * @param aToken * @param aParser * @return @@ -706,7 +699,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ if(gHTMLElements[eHTMLTag_body].SectionContains(theTag,PR_TRUE)){ mTokenizer->PushTokenFront(aToken); //put this token back... mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content - theToken=(CHTMLToken*)mTokenRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body); + theToken=(CHTMLToken*)mTokenRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body,"body"); theType=eToken_start; //now open a body... } @@ -735,20 +728,29 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ case eToken_whitespace: case eToken_newline: result=HandleStartToken(theToken); break; + case eToken_end: result=HandleEndToken(theToken); break; + + case eToken_cdatasection: case eToken_comment: result=HandleCommentToken(theToken); break; + case eToken_entity: result=HandleEntityToken(theToken); break; + case eToken_attribute: result=HandleAttributeToken(theToken); break; + case eToken_style: result=HandleStyleToken(theToken); break; + case eToken_instruction: result=HandleProcessingInstructionToken(theToken); break; + case eToken_doctypeDecl: result=HandleDocTypeDeclToken(theToken); break; + default: break; }//switch @@ -1244,7 +1246,6 @@ nsresult CNavDTD::HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags nsresult CNavDTD::HandleStartToken(CToken* aToken) { NS_PRECONDITION(0!=aToken,kNullToken); - #ifdef RICKG_DEBUG WriteTokenToLog(aToken); #endif @@ -1253,7 +1254,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { nsCParserNode* theNode=CreateNode(); theNode->Init(aToken,mLineNumber,mTokenRecycler); - + eHTMLTags theChildTag=(eHTMLTags)aToken->GetTypeID(); PRInt16 attrCount=aToken->GetAttributeCount(); eHTMLTags theParent=mBodyContext->Last(); diff --git a/mozilla/parser/htmlparser/src/COtherDTD.cpp b/mozilla/parser/htmlparser/src/COtherDTD.cpp index 8a49847de9c..cd656990ee3 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.cpp +++ b/mozilla/parser/htmlparser/src/COtherDTD.cpp @@ -337,7 +337,7 @@ NS_IMETHODIMP COtherDTD::ConvertEntityToUnicode(const nsString& aEntity, PRInt32 * @param aTag -- tag to test for containership * @return PR_TRUE if given tag can contain other tags */ -PRBool COtherDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRInt32 aParentContains) const { +PRBool COtherDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRBool& aParentContains) const { return CNavDTD::CanOmit(aParent,aChild,aParentContains); } diff --git a/mozilla/parser/htmlparser/src/COtherDTD.h b/mozilla/parser/htmlparser/src/COtherDTD.h index 547946211b0..fd1bc877f7c 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.h +++ b/mozilla/parser/htmlparser/src/COtherDTD.h @@ -123,7 +123,7 @@ class COtherDTD : public CNavDTD { * @param aTag -- tag to test for containership * @return PR_TRUE if given tag can contain other tags */ - virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRInt32 aParentContains)const; + virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild,PRBool& aParentContains) const; /** * Give rest of world access to our tag enums, so that CanContain(), etc, diff --git a/mozilla/parser/htmlparser/src/nsElementTable.cpp b/mozilla/parser/htmlparser/src/nsElementTable.cpp index c0730053b4d..526e45e652e 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.cpp +++ b/mozilla/parser/htmlparser/src/nsElementTable.cpp @@ -956,7 +956,7 @@ void InitializeElementTable(void) { Initialize( /*tag*/ eHTMLTag_p, /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, - /*rootnodes,endrootnodes*/ &gInBody,&gInBody, + /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,&gDontAutoClose, /*parent,incl,exclgroups*/ kBlock, kInlineEntity, kNone, //this used to contain FLOW. But it's really an inline container. /*special props, prop-range*/ 0,kDefaultPropRange, //otherwise it tries to contain things like H1..H6 diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp index 590aeb0ef3d..98fdcc68f04 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp @@ -322,7 +322,7 @@ nsresult nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner) { break; } //switch - return NS_OK; + return result; } @@ -692,8 +692,11 @@ nsresult nsHTMLTokenizer::ConsumeSpecialMarkup(PRUnichar aChar,CToken*& aToken,n PRInt32 theIndex=theBufCopy.Find("DOCTYPE"); CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - if(theIndex==kNotFound) - aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment); + if(theIndex==kNotFound) { + if('['==theBufCopy.CharAt(0)) + aToken = theRecycler->CreateTokenOfType(eToken_cdatasection,eHTMLTag_comment); + else aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment); + } else aToken = theRecycler->CreateTokenOfType(eToken_doctypeDecl,eHTMLTag_markupDecl); diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp index 17aabee8a7f..88dccf4c3a8 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp @@ -1935,39 +1935,19 @@ const nsParserError * CErrorToken::GetError(void) CDoctypeDeclToken::CDoctypeDeclToken(eHTMLTags aTag) : CHTMLToken(aTag) { } +/** + * This method consumes a doctype element. + * Note: I'm rewriting this method to seek to the first <, since quotes can really screw us up. + * + * @update gess 9/23/98 + * @param + * @return + */ nsresult CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aMode) { - nsresult result=NS_OK; mTextValue="["; - PRBool done=PR_FALSE; - - result=aScanner.ReadUntil(mTextValue,theTerminals,PR_TRUE,PR_FALSE); - - while(!done && NS_OK==result){ - result=aScanner.Peek(aChar); - if(result==NS_OK) { - if(kQuote==aChar) { - result=aScanner.GetChar(aChar); - if(NS_OK==result) mTextValue += aChar; // append the quote that you just got - result=aScanner.ReadUntil(mTextValue,kQuote,PR_TRUE); - if(NS_OK==result && aMode!=eParseMode_noquirks) - result=aScanner.ReadWhile(mTextValue,"\"",PR_TRUE,PR_FALSE); // consume multiple quotes - } - else if(kLeftSquareBracket==aChar) { - result=aScanner.ReadUntil(mTextValue,kRightSquareBracket,PR_TRUE); - } - else if(kGreaterThan==aChar){ - result=aScanner.ReadUntil(mTextValue,kGreaterThan,PR_TRUE); - done=PR_TRUE; - } - else { - result=aScanner.GetChar(aChar); - if(result==NS_OK) mTextValue += aChar; - } - } - } + nsresult result=aScanner.ReadUntil(mTextValue,'<',PR_FALSE); return result; } diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index 9f02e7ba47a..2c1110a8da2 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -798,6 +798,12 @@ nsresult nsParser::Parse(const nsString& aSourceBuffer,void* aKey,const nsString //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! + +#if 0 + //this is only for debug purposes + aSourceBuffer.DebugDump(); +#endif + nsresult result=NS_OK; nsParser* me = this; // Maintain a reference to ourselves so we don't go away diff --git a/mozilla/parser/htmlparser/src/nsScanner.cpp b/mozilla/parser/htmlparser/src/nsScanner.cpp index b22dd8c5839..1f26168aa14 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.cpp +++ b/mozilla/parser/htmlparser/src/nsScanner.cpp @@ -608,6 +608,7 @@ nsresult nsScanner::SkipPast(nsString& aValidSet){ return NS_OK; } + /** * Consume characters until you find the terminal char * @@ -652,7 +653,8 @@ nsresult nsScanner::ReadIdentifier(nsString& aString) { } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -698,7 +700,8 @@ nsresult nsScanner::ReadNumber(nsString& aString) { } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -747,7 +750,8 @@ nsresult nsScanner::ReadWhitespace(nsString& aString) { } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -794,7 +798,8 @@ nsresult nsScanner::ReadWhile(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -842,7 +847,8 @@ nsresult nsScanner::ReadWhile(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -921,7 +927,8 @@ nsresult nsScanner::ReadUntil(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -970,7 +977,8 @@ nsresult nsScanner::ReadUntil(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],mOffset-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],mOffset-theOrigin); result=Peek(theChar); theBuf=mBuffer.GetUnicode(); theOrigin=mOffset; @@ -1042,7 +1050,8 @@ nsresult nsScanner::ReadUntil(nsString& aString, } } else { - aString.Append(&theBuf[theOrigin],theLen-theOrigin-1); + mOffset -= 1; + aString.Append(&theBuf[theOrigin],theLen-theOrigin); mOffset=theLen; result=Peek(theChar); theLen=mBuffer.Length(); diff --git a/mozilla/parser/htmlparser/src/nsScanner.h b/mozilla/parser/htmlparser/src/nsScanner.h index 813da1ee0f4..57a499f9604 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.h +++ b/mozilla/parser/htmlparser/src/nsScanner.h @@ -316,6 +316,7 @@ class nsScanner { protected: + enum {eBufferSizeThreshold=0x1000}; //4K /** diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp index 16a9f3c2063..45f4826c06d 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -208,7 +208,7 @@ public: CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mStartTag("start"), mEndTag("end"), mCommentTag("comment"), mDocTypeTag("doctype"), mPITag("pi"), mEntityTag("entity"), - mText("txt"), mKey("key"), mValue("val") + mText("txt"), mKey("key"), mValue("val"), mCDATATag("cdata") { NS_INIT_REFCNT(); mParser=0; @@ -877,6 +877,15 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { result=WriteTag(mEndTag,aToken,0,PR_TRUE); break; + case eToken_cdatasection: + { + nsString& theStr=aToken->GetStringValueXXX(); + theStr.Insert(""); + result=WriteTag(mCDATATag,aToken,0,PR_TRUE); + } + break; + case eToken_comment: result=WriteTag(mCommentTag,aToken,0,PR_TRUE); break; diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h index ead2d604a71..1bd26fd9939 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h @@ -273,6 +273,7 @@ protected: nsAutoString mStartTag; nsAutoString mEndTag; nsAutoString mCommentTag; + nsAutoString mCDATATag; nsAutoString mDocTypeTag; nsAutoString mPITag; nsAutoString mEntityTag;