From bc0e95071fc6d68d0035424b7d2a90680e80a2ce Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Thu, 8 Apr 1999 11:36:29 +0000 Subject: [PATCH] fixed token bug in parser that caused script error --- htmlparser/src/CNavDTD.cpp | 105 +++++++----- htmlparser/src/nsElementTable.cpp | 267 ++++++++++++++++-------------- parser/htmlparser/src/CNavDTD.cpp | 105 +++++++----- 3 files changed, 264 insertions(+), 213 deletions(-) diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 18a10a61e22..637cc41bf41 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -43,7 +43,7 @@ #endif #include "prmem.h" -#define RICKG_DEBUG 0 +#define RICKG_DEBUG 1 #ifdef RICKG_DEBUG #include #endif @@ -481,6 +481,7 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString return result; } +CTokenRecycler* gRecycler=0; /** * This is called when it's time to read as many tokens from the tokenizer @@ -498,18 +499,12 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke nsITokenizer* oldTokenizer=mTokenizer; mTokenizer=aTokenizer; mParser=(nsParser*)aParser; - nsITokenRecycler* theRecycler=aTokenizer->GetTokenRecycler(); mSink=(nsIHTMLContentSink*)aSink; + gRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler(); while(NS_OK==result){ CToken* theToken=mTokenizer->PopToken(); if(theToken) { result=HandleToken(theToken,aParser); - if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { - theRecycler->RecycleToken(theToken); - } - else if(NS_ERROR_HTMLPARSER_MISPLACED!=result) - mTokenizer->PushTokenFront(theToken); - else result=NS_OK; } else break; }//while @@ -608,29 +603,40 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType()); eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID(); - - //Ok, now the real work begins. - //First, find out which section of the document the tag is supposed to go into. - //If that section is not open, push this tag (and it's attributes) onto the misplacedContent deque. - - static eHTMLTags docElements[]= - {eHTMLTag_html,eHTMLTag_body,eHTMLTag_head,eHTMLTag_frameset,eHTMLTag_comment,eHTMLTag_newline,eHTMLTag_whitespace}; - if(!mHadBodyOrFrameset){ - PRBool isHeadChild=gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag); - if((!isHeadChild) && (mHasOpenScript || (!FindTagInSet(theTag,docElements,sizeof(docElements)/sizeof(eHTMLTag_unknown))))){ - //really we want to push the token and all its skipped content and attributes... - mMisplacedContent.Push(theToken); - theToken=0; //force us to fall to bottom of this method... - result=NS_ERROR_HTMLPARSER_MISPLACED; + static eHTMLTags passThru[]= {eHTMLTag_html,eHTMLTag_comment,eHTMLTag_newline,eHTMLTag_whitespace,eHTMLTag_script}; + if(!FindTagInSet(theTag,passThru,sizeof(passThru)/sizeof(eHTMLTag_unknown))){ + if(!gHTMLElements[eHTMLTag_html].SectionContains(theTag,PR_FALSE)) { + if(!mHadBodyOrFrameset){ + if(mHasOpenHead) { + //just fall through and handle current token + if(!gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag)){ + mMisplacedContent.Push(aToken); + return result; + } + } + else { + if(gHTMLElements[eHTMLTag_body].SectionContains(theTag,PR_TRUE)){ + mTokenizer->PushTokenFront(aToken); //put this token back... + mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content + theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body); + //now open a body... + } + } + } } - } + } if(theToken){ - CITokenHandler* theHandler=GetTokenHandler(theType); if(theHandler) { mParser=(nsParser*)aParser; result=(*theHandler)(theToken,this); + if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { + gRecycler->RecycleToken(theToken); + } + else if(NS_ERROR_HTMLPARSER_MISPLACED!=result) + mTokenizer->PushTokenFront(theToken); + else result=NS_OK; if (mDTDDebug) { //mDTDDebug->Verify(this, mParser, mBodyContext->GetCount(), mBodyContext->mTags, mFilename); } @@ -846,6 +852,7 @@ PRBool CanBeContained(eHTMLTags aParentTag,eHTMLTags aChildTag,nsTagStack& aTagS * 1.