From 7a884e73a4e583cc08d65b9677e1d0b152771d6d Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Wed, 7 Jul 1999 07:40:35 +0000 Subject: [PATCH] fix bugs 8523, 9127, parially fix 8803 --- htmlparser/src/CNavDTD.cpp | 51 ++++++++++++++----- htmlparser/src/CNavDTD.h | 3 +- htmlparser/src/COtherDTD.cpp | 1 - htmlparser/src/SelfTest.cpp | 4 +- htmlparser/src/nsDTDDebug.cpp | 1 - htmlparser/src/nsDTDUtils.cpp | 5 ++ htmlparser/src/nsDTDUtils.h | 1 - htmlparser/src/nsElementTable.cpp | 16 ++++-- htmlparser/src/nsElementTable.h | 1 + htmlparser/src/nsHTMLContentSinkStream.cpp | 1 - htmlparser/src/nsHTMLNullSink.cpp | 1 - htmlparser/src/nsHTMLToTXTSinkStream.cpp | 1 - htmlparser/src/nsHTMLTokens.cpp | 14 ++--- htmlparser/src/nsHTMLTokens.h | 1 - htmlparser/src/nsParser.cpp | 9 +--- htmlparser/src/nsToken.cpp | 8 +++ htmlparser/src/nsToken.h | 6 ++- htmlparser/src/nsXIFDTD.h | 1 - parser/htmlparser/src/CNavDTD.cpp | 51 ++++++++++++++----- parser/htmlparser/src/CNavDTD.h | 3 +- parser/htmlparser/src/COtherDTD.cpp | 1 - parser/htmlparser/src/SelfTest.cpp | 4 +- parser/htmlparser/src/nsDTDDebug.cpp | 1 - parser/htmlparser/src/nsDTDUtils.cpp | 5 ++ parser/htmlparser/src/nsDTDUtils.h | 1 - parser/htmlparser/src/nsElementTable.cpp | 16 ++++-- parser/htmlparser/src/nsElementTable.h | 1 + .../src/nsHTMLContentSinkStream.cpp | 1 - parser/htmlparser/src/nsHTMLNullSink.cpp | 1 - .../htmlparser/src/nsHTMLToTXTSinkStream.cpp | 1 - parser/htmlparser/src/nsHTMLTokens.cpp | 14 ++--- parser/htmlparser/src/nsHTMLTokens.h | 1 - parser/htmlparser/src/nsParser.cpp | 9 +--- parser/htmlparser/src/nsToken.cpp | 8 +++ parser/htmlparser/src/nsToken.h | 6 ++- parser/htmlparser/src/nsXIFDTD.h | 1 - 36 files changed, 166 insertions(+), 84 deletions(-) diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index d619d1227bf9..59bc7e360f7e 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -40,7 +40,6 @@ #ifdef XP_PC #include //this is here for debug reasons... -#include #endif #include "prmem.h" @@ -476,7 +475,8 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString mFilename=aFilename; mHasOpenBody=PR_FALSE; - mHadBodyOrFrameset=PR_FALSE; + mHadBody=PR_FALSE; + mHadFrameset=PR_FALSE; mLineNumber=1; mHasOpenScript=PR_FALSE; mSink=(nsIHTMLContentSink*)aSink; @@ -542,7 +542,7 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){ nsresult result= NS_OK; - if((NS_OK==anErrorCode) && (!mHadBodyOrFrameset)) { + if((NS_OK==anErrorCode) && (!mHadBody) && (!mHadFrameset)) { CStartToken theToken(eHTMLTag_body); //open the body container... result=HandleStartToken(&theToken); mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content @@ -625,6 +625,8 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID(); PRBool execSkipContent=PR_FALSE; + theToken->mRecycle=PR_TRUE; //assume every token coming into this system needs recycling. + /* --------------------------------------------------------------------------------- To understand this little piece of code, you need to look below too. In essence, this code caches "skipped content" until we find a given skiptarget. @@ -658,11 +660,12 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ 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((!mHadBody) && (!mHadFrameset)){ if(mHasOpenHead) { //just fall through and handle current token if(!gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag)){ mMisplacedContent.Push(aToken); + aToken->mRecycle=PR_FALSE; return result; } } @@ -695,7 +698,8 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ mParser=(nsParser*)aParser; result=(*theHandler)(theToken,this); if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { - gRecycler->RecycleToken(theToken); + if(theToken->mRecycle) + gRecycler->RecycleToken(theToken); } else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) return result; @@ -755,10 +759,6 @@ nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){ nsresult result=NS_OK; switch(aChildTag){ - case eHTMLTag_body: - case eHTMLTag_frameset: - mHadBodyOrFrameset=PR_TRUE; - break; case eHTMLTag_pre: case eHTMLTag_listing: @@ -1280,12 +1280,13 @@ nsresult CNavDTD::HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags //of another section. If it is, the cache it for later. // 1. Get the root node for the child. See if the ultimate node is the BODY, FRAMESET, HEAD or HTML PRInt32 theTagCount = mBodyContext->GetCount(); + PRInt32 attrCount = aToken->GetAttributeCount(); if(gHTMLElements[aParent].HasSpecialProperty(kBadContentWatch)) { eHTMLTags theTag; PRInt32 theBCIndex; PRBool isNotWhiteSpace = PR_FALSE; - PRInt32 attrCount = aToken->GetAttributeCount(); + while(theTagCount > 0) { theTag = mBodyContext->TagAt(--theTagCount); if(!gHTMLElements[theTag].HasSpecialProperty(kBadContentWatch)) { @@ -1314,6 +1315,24 @@ nsresult CNavDTD::HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags result=NS_ERROR_HTMLPARSER_MISPLACED; } } + + if((aChildTag!=aParent) && (gHTMLElements[aParent].HasSpecialProperty(kSaveMisplaced))) { + mMisplacedContent.Push(aToken); + aToken->mRecycle=PR_FALSE; + + // If the token is attributed then save those attributes too. + if(attrCount > 0) { + nsCParserNode* theAttrNode = (nsCParserNode*)&aNode; + while(attrCount > 0){ + CToken* theToken=theAttrNode->PopAttributeToken(); + if(theToken){ + mMisplacedContent.Push(theToken); + theToken->mRecycle=PR_FALSE; + } + attrCount--; + } + } + } return result; } @@ -1356,7 +1375,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { return OpenContainer(attrNode,PR_FALSE); break; case eHTMLTag_head: - if(mHadBodyOrFrameset) { + if(mHadBody || mHadFrameset) { result=HandleOmittedTag(aToken,theChildTag,theParent,attrNode); if(result == NS_OK) return result; @@ -1985,6 +2004,10 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const { } } + if(gHTMLElements[aParent].HasSpecialProperty(kSaveMisplaced)) { + return PR_TRUE; + } + return PR_FALSE; } @@ -2339,6 +2362,8 @@ nsresult CNavDTD::OpenBody(const nsIParserNode& aNode){ nsresult result=NS_OK; + mHadBody=PR_TRUE; + PRInt32 theHTMLPos=GetTopmostIndexOf(eHTMLTag_html); if(kNotFound==theHTMLPos){ //someone forgot to open HTML. Let's do it for them. nsAutoString theEmpty; @@ -2463,9 +2488,11 @@ nsresult CNavDTD::CloseMap(const nsIParserNode& aNode){ */ nsresult CNavDTD::OpenFrameset(const nsIParserNode& aNode){ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos); + + mHadFrameset=PR_TRUE; nsresult result=(mSink) ? mSink->OpenFrameset(aNode) : NS_OK; mBodyContext->Push((eHTMLTags)aNode.GetNodeType()); - mHadBodyOrFrameset=PR_TRUE; + mHadFrameset=PR_TRUE; return result; } diff --git a/htmlparser/src/CNavDTD.h b/htmlparser/src/CNavDTD.h index 8af41fa18867..b2ee3040499c 100644 --- a/htmlparser/src/CNavDTD.h +++ b/htmlparser/src/CNavDTD.h @@ -509,7 +509,8 @@ protected: PRBool mHasOpenMap; PRInt32 mHasOpenHead; PRBool mHasOpenBody; - PRBool mHadBodyOrFrameset; + PRBool mHadFrameset; + PRBool mHadBody; nsString mFilename; nsIDTDDebug* mDTDDebug; PRInt32 mLineNumber; diff --git a/htmlparser/src/COtherDTD.cpp b/htmlparser/src/COtherDTD.cpp index c71d8255066a..5bb426bcd50b 100644 --- a/htmlparser/src/COtherDTD.cpp +++ b/htmlparser/src/COtherDTD.cpp @@ -44,7 +44,6 @@ #include "prtypes.h" #include "prio.h" #include "plstr.h" -#include #ifdef XP_PC diff --git a/htmlparser/src/SelfTest.cpp b/htmlparser/src/SelfTest.cpp index 34da8e47c209..066c85b7f730 100644 --- a/htmlparser/src/SelfTest.cpp +++ b/htmlparser/src/SelfTest.cpp @@ -37,7 +37,6 @@ #define PARSER_DLL "libraptorhtmlpars"MOZ_DLL_SUFFIX #endif -ofstream filelist("filelist.out"); PRBool compareFiles(const char* file1,const char* file2,int& failpos) { PRBool result=PR_TRUE; @@ -131,7 +130,8 @@ void parseFile (const char* aFilename,int size) int failpos=0; if(!compareFiles(aFilename,filename,failpos)) { - filelist << "FAILED: " << aFilename << "[" << failpos << "]" << endl; + char buffer[100]; + printf("FAILED: %s [%i]\n",aFilename,failpos); } } diff --git a/htmlparser/src/nsDTDDebug.cpp b/htmlparser/src/nsDTDDebug.cpp index fd2b9497910f..9303cd8d1886 100644 --- a/htmlparser/src/nsDTDDebug.cpp +++ b/htmlparser/src/nsDTDDebug.cpp @@ -36,7 +36,6 @@ #include "prio.h" #include "plstr.h" #include "prstrm.h" -#include #include #include "prmem.h" #include "nsQuickSort.h" diff --git a/htmlparser/src/nsDTDUtils.cpp b/htmlparser/src/nsDTDUtils.cpp index 14365e50a5f1..ad3ff6d3cce3 100644 --- a/htmlparser/src/nsDTDUtils.cpp +++ b/htmlparser/src/nsDTDUtils.cpp @@ -549,6 +549,10 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag) } void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle) { +#ifdef RICKG_DEBUG + +#include + const char* prefix=" "; fstream out(aFilename,ios::out); out << "==================================================" << endl; @@ -578,6 +582,7 @@ void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* } else out<<"(not container)" << endl; } +#endif } diff --git a/htmlparser/src/nsDTDUtils.h b/htmlparser/src/nsDTDUtils.h index e78ae89375a2..4ab22d90a4b7 100644 --- a/htmlparser/src/nsDTDUtils.h +++ b/htmlparser/src/nsDTDUtils.h @@ -34,7 +34,6 @@ #include "nsCRT.h" #include "nsDeque.h" #include "nsIDTD.h" -#include #include "nsITokenizer.h" #include "nsString.h" #include "nsIElementObserver.h" diff --git a/htmlparser/src/nsElementTable.cpp b/htmlparser/src/nsElementTable.cpp index 38dd5461496f..9a774f90dc59 100644 --- a/htmlparser/src/nsElementTable.cpp +++ b/htmlparser/src/nsElementTable.cpp @@ -477,7 +477,7 @@ nsHTMLElement gHTMLElements[] = { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0, - /*parent,incl,exclgroups*/ kBlock, kFlowEntity, kNone, + /*parent,incl,exclgroups*/ kBlock, kSelf|kFlowEntity, kNone, /*special props, prop-range*/ kOmitWS, kNoPropRange, /*special parents,kids,skip*/ 0,&gDLKids,eHTMLTag_unknown}, @@ -623,7 +623,7 @@ nsHTMLElement gHTMLElements[] = { /*rootnodes,endrootnodes*/ &gHTMLRootTags, &gHTMLRootTags, /*autoclose starttags and endtags*/ 0,0,0, /*parent,incl,exclgroups*/ kNone, kHTMLContent, kNone, - /*special props, prop-range*/ kOmitEndTag|kOmitWS|kNoStyleLeaksIn, kDefaultPropRange, + /*special props, prop-range*/ kSaveMisplaced|kOmitEndTag|kOmitWS|kNoStyleLeaksIn, kDefaultPropRange, /*special parents,kids,skip*/ 0,&gHtmlKids,eHTMLTag_unknown}, { /*tag*/ eHTMLTag_i, @@ -1712,6 +1712,7 @@ PRBool nsHTMLElement::HasSpecialProperty(PRInt32 aProperty) const{ } void nsHTMLElement::DebugDumpContainment(const char* aFilename,const char* aTitle){ +#ifdef RICKG_DEBUG PRBool t=CanContain(eHTMLTag_address,eHTMLTag_object); @@ -1761,9 +1762,12 @@ void nsHTMLElement::DebugDumpContainment(const char* aFilename,const char* aTitl linenum++; } } //for +#endif } void nsHTMLElement::DebugDumpMembership(const char* aFilename){ +#ifdef RICKG_DEBUG + const char* prefix=" "; const char* suffix=" "; const char* shortSuffix=" "; @@ -1815,10 +1819,13 @@ void nsHTMLElement::DebugDumpMembership(const char* aFilename){ out << answer[gHTMLElements[eHTMLTags(i)].mParentBits==kPreformatted] << suffix << endl; */ } //for - out< #include #include "nsString.h" #include "nsIParser.h" diff --git a/htmlparser/src/nsHTMLNullSink.cpp b/htmlparser/src/nsHTMLNullSink.cpp index 6a254080d7ec..baf70f3f9d0e 100644 --- a/htmlparser/src/nsHTMLNullSink.cpp +++ b/htmlparser/src/nsHTMLNullSink.cpp @@ -20,7 +20,6 @@ #include "nsHTMLTokens.h" #include "nsIParser.h" #include "prtypes.h" -#include #define VERBOSE_DEBUG diff --git a/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/htmlparser/src/nsHTMLToTXTSinkStream.cpp index 72b882166ed3..53c61b0791cc 100644 --- a/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -29,7 +29,6 @@ #include "nsHTMLToTXTSinkStream.h" #include "nsHTMLTokens.h" -#include #include "nsString.h" #include "nsIParser.h" #include "nsHTMLEntities.h" diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp index 70b119a1c15b..0225d4ade4fb 100644 --- a/htmlparser/src/nsHTMLTokens.cpp +++ b/htmlparser/src/nsHTMLTokens.cpp @@ -820,13 +820,15 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) aString+=aChar; } - theRightChars.Truncate(0); - aString.Right(theRightChars,5); - theRightChars.StripChars(" "); + if(NS_OK==result){ + theRightChars.Truncate(0); + aString.Right(theRightChars,5); + theRightChars.StripChars(" "); - findpos=theRightChars.RFind("-->"); - if(kNotFound==findpos) - findpos=theRightChars.RFind("!>"); + findpos=theRightChars.RFind("-->"); + if(kNotFound==findpos) + findpos=theRightChars.RFind("!>"); + } } //while return result; } //if diff --git a/htmlparser/src/nsHTMLTokens.h b/htmlparser/src/nsHTMLTokens.h index 4e272bf14b00..ed93b4ffc892 100644 --- a/htmlparser/src/nsHTMLTokens.h +++ b/htmlparser/src/nsHTMLTokens.h @@ -42,7 +42,6 @@ #include "nsToken.h" #include "nsHTMLTags.h" #include "nsParserError.h" -#include #include "nsString.h" class nsScanner; diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index 9903a77ea6db..4e32b73bb747 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -25,7 +25,6 @@ #include "nsScanner.h" #include "prenv.h" //this is here for debug reasons... #include "plstr.h" -#include #include "nsIParserFilter.h" #include "nshtmlpars.h" #include "CNavDTD.h" @@ -711,13 +710,6 @@ nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled, void* aK */ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aVerifyEnabled,PRBool aLastCall){ -#ifdef _rickgdebug - { - fstream out("c:/temp/parseout.file",ios::trunc); - aSourceBuffer.DebugDump(out); - } -#endif - //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! @@ -1024,6 +1016,7 @@ nsParser::OnStatus(nsIURI* aURL, const PRUnichar* aMsg) } #ifdef rickgdebug +#include fstream* gDumpFile; #endif diff --git a/htmlparser/src/nsToken.cpp b/htmlparser/src/nsToken.cpp index 0c72ee21a59a..c2fbcd0d53fe 100644 --- a/htmlparser/src/nsToken.cpp +++ b/htmlparser/src/nsToken.cpp @@ -38,6 +38,8 @@ CToken::CToken(PRInt32 aTag) : mTextValue() { mTypeID=aTag; mAttrCount=0; TokenCount++; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** @@ -50,6 +52,8 @@ CToken::CToken(const nsString& aName) : mTextValue(aName) { mTypeID=0; mAttrCount=0; TokenCount++; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** @@ -62,6 +66,8 @@ CToken::CToken(const char* aName) : mTextValue(aName) { mTypeID=0; mAttrCount=0; TokenCount++; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** @@ -89,6 +95,8 @@ void CToken::Reinitialize(PRInt32 aTag, const nsString& aString){ mAttrCount=0; mTypeID=aTag; mAttrCount=0; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** diff --git a/htmlparser/src/nsToken.h b/htmlparser/src/nsToken.h index a5c52724d562..1d83c44b821e 100644 --- a/htmlparser/src/nsToken.h +++ b/htmlparser/src/nsToken.h @@ -37,7 +37,6 @@ #include "prtypes.h" #include "nsString.h" -#include #include "nsError.h" class nsScanner; @@ -55,6 +54,8 @@ class nsScanner; class CToken { public: + enum eTokenOrigin {eSource,eResidualStyle}; + /** * Default constructor * @update gess7/21/98 @@ -195,6 +196,9 @@ class CToken { static int GetTokenCount(); + eTokenOrigin mOrigin; + PRBool mRecycle; + protected: PRInt32 mTypeID; PRInt16 mAttrCount; diff --git a/htmlparser/src/nsXIFDTD.h b/htmlparser/src/nsXIFDTD.h index 88fe58f94149..e5c46f9aafe9 100644 --- a/htmlparser/src/nsXIFDTD.h +++ b/htmlparser/src/nsXIFDTD.h @@ -35,7 +35,6 @@ #include "nsIContentSink.h" #include "nsHTMLTokens.h" #include "nsVoidArray.h" -#include #define NS_XIF_DTD_IID \ diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index d619d1227bf9..59bc7e360f7e 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -40,7 +40,6 @@ #ifdef XP_PC #include //this is here for debug reasons... -#include #endif #include "prmem.h" @@ -476,7 +475,8 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString mFilename=aFilename; mHasOpenBody=PR_FALSE; - mHadBodyOrFrameset=PR_FALSE; + mHadBody=PR_FALSE; + mHadFrameset=PR_FALSE; mLineNumber=1; mHasOpenScript=PR_FALSE; mSink=(nsIHTMLContentSink*)aSink; @@ -542,7 +542,7 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){ nsresult result= NS_OK; - if((NS_OK==anErrorCode) && (!mHadBodyOrFrameset)) { + if((NS_OK==anErrorCode) && (!mHadBody) && (!mHadFrameset)) { CStartToken theToken(eHTMLTag_body); //open the body container... result=HandleStartToken(&theToken); mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content @@ -625,6 +625,8 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID(); PRBool execSkipContent=PR_FALSE; + theToken->mRecycle=PR_TRUE; //assume every token coming into this system needs recycling. + /* --------------------------------------------------------------------------------- To understand this little piece of code, you need to look below too. In essence, this code caches "skipped content" until we find a given skiptarget. @@ -658,11 +660,12 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ 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((!mHadBody) && (!mHadFrameset)){ if(mHasOpenHead) { //just fall through and handle current token if(!gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag)){ mMisplacedContent.Push(aToken); + aToken->mRecycle=PR_FALSE; return result; } } @@ -695,7 +698,8 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ mParser=(nsParser*)aParser; result=(*theHandler)(theToken,this); if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { - gRecycler->RecycleToken(theToken); + if(theToken->mRecycle) + gRecycler->RecycleToken(theToken); } else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) return result; @@ -755,10 +759,6 @@ nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){ nsresult result=NS_OK; switch(aChildTag){ - case eHTMLTag_body: - case eHTMLTag_frameset: - mHadBodyOrFrameset=PR_TRUE; - break; case eHTMLTag_pre: case eHTMLTag_listing: @@ -1280,12 +1280,13 @@ nsresult CNavDTD::HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags //of another section. If it is, the cache it for later. // 1. Get the root node for the child. See if the ultimate node is the BODY, FRAMESET, HEAD or HTML PRInt32 theTagCount = mBodyContext->GetCount(); + PRInt32 attrCount = aToken->GetAttributeCount(); if(gHTMLElements[aParent].HasSpecialProperty(kBadContentWatch)) { eHTMLTags theTag; PRInt32 theBCIndex; PRBool isNotWhiteSpace = PR_FALSE; - PRInt32 attrCount = aToken->GetAttributeCount(); + while(theTagCount > 0) { theTag = mBodyContext->TagAt(--theTagCount); if(!gHTMLElements[theTag].HasSpecialProperty(kBadContentWatch)) { @@ -1314,6 +1315,24 @@ nsresult CNavDTD::HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags result=NS_ERROR_HTMLPARSER_MISPLACED; } } + + if((aChildTag!=aParent) && (gHTMLElements[aParent].HasSpecialProperty(kSaveMisplaced))) { + mMisplacedContent.Push(aToken); + aToken->mRecycle=PR_FALSE; + + // If the token is attributed then save those attributes too. + if(attrCount > 0) { + nsCParserNode* theAttrNode = (nsCParserNode*)&aNode; + while(attrCount > 0){ + CToken* theToken=theAttrNode->PopAttributeToken(); + if(theToken){ + mMisplacedContent.Push(theToken); + theToken->mRecycle=PR_FALSE; + } + attrCount--; + } + } + } return result; } @@ -1356,7 +1375,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { return OpenContainer(attrNode,PR_FALSE); break; case eHTMLTag_head: - if(mHadBodyOrFrameset) { + if(mHadBody || mHadFrameset) { result=HandleOmittedTag(aToken,theChildTag,theParent,attrNode); if(result == NS_OK) return result; @@ -1985,6 +2004,10 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const { } } + if(gHTMLElements[aParent].HasSpecialProperty(kSaveMisplaced)) { + return PR_TRUE; + } + return PR_FALSE; } @@ -2339,6 +2362,8 @@ nsresult CNavDTD::OpenBody(const nsIParserNode& aNode){ nsresult result=NS_OK; + mHadBody=PR_TRUE; + PRInt32 theHTMLPos=GetTopmostIndexOf(eHTMLTag_html); if(kNotFound==theHTMLPos){ //someone forgot to open HTML. Let's do it for them. nsAutoString theEmpty; @@ -2463,9 +2488,11 @@ nsresult CNavDTD::CloseMap(const nsIParserNode& aNode){ */ nsresult CNavDTD::OpenFrameset(const nsIParserNode& aNode){ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos); + + mHadFrameset=PR_TRUE; nsresult result=(mSink) ? mSink->OpenFrameset(aNode) : NS_OK; mBodyContext->Push((eHTMLTags)aNode.GetNodeType()); - mHadBodyOrFrameset=PR_TRUE; + mHadFrameset=PR_TRUE; return result; } diff --git a/parser/htmlparser/src/CNavDTD.h b/parser/htmlparser/src/CNavDTD.h index 8af41fa18867..b2ee3040499c 100644 --- a/parser/htmlparser/src/CNavDTD.h +++ b/parser/htmlparser/src/CNavDTD.h @@ -509,7 +509,8 @@ protected: PRBool mHasOpenMap; PRInt32 mHasOpenHead; PRBool mHasOpenBody; - PRBool mHadBodyOrFrameset; + PRBool mHadFrameset; + PRBool mHadBody; nsString mFilename; nsIDTDDebug* mDTDDebug; PRInt32 mLineNumber; diff --git a/parser/htmlparser/src/COtherDTD.cpp b/parser/htmlparser/src/COtherDTD.cpp index c71d8255066a..5bb426bcd50b 100644 --- a/parser/htmlparser/src/COtherDTD.cpp +++ b/parser/htmlparser/src/COtherDTD.cpp @@ -44,7 +44,6 @@ #include "prtypes.h" #include "prio.h" #include "plstr.h" -#include #ifdef XP_PC diff --git a/parser/htmlparser/src/SelfTest.cpp b/parser/htmlparser/src/SelfTest.cpp index 34da8e47c209..066c85b7f730 100644 --- a/parser/htmlparser/src/SelfTest.cpp +++ b/parser/htmlparser/src/SelfTest.cpp @@ -37,7 +37,6 @@ #define PARSER_DLL "libraptorhtmlpars"MOZ_DLL_SUFFIX #endif -ofstream filelist("filelist.out"); PRBool compareFiles(const char* file1,const char* file2,int& failpos) { PRBool result=PR_TRUE; @@ -131,7 +130,8 @@ void parseFile (const char* aFilename,int size) int failpos=0; if(!compareFiles(aFilename,filename,failpos)) { - filelist << "FAILED: " << aFilename << "[" << failpos << "]" << endl; + char buffer[100]; + printf("FAILED: %s [%i]\n",aFilename,failpos); } } diff --git a/parser/htmlparser/src/nsDTDDebug.cpp b/parser/htmlparser/src/nsDTDDebug.cpp index fd2b9497910f..9303cd8d1886 100644 --- a/parser/htmlparser/src/nsDTDDebug.cpp +++ b/parser/htmlparser/src/nsDTDDebug.cpp @@ -36,7 +36,6 @@ #include "prio.h" #include "plstr.h" #include "prstrm.h" -#include #include #include "prmem.h" #include "nsQuickSort.h" diff --git a/parser/htmlparser/src/nsDTDUtils.cpp b/parser/htmlparser/src/nsDTDUtils.cpp index 14365e50a5f1..ad3ff6d3cce3 100644 --- a/parser/htmlparser/src/nsDTDUtils.cpp +++ b/parser/htmlparser/src/nsDTDUtils.cpp @@ -549,6 +549,10 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag) } void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle) { +#ifdef RICKG_DEBUG + +#include + const char* prefix=" "; fstream out(aFilename,ios::out); out << "==================================================" << endl; @@ -578,6 +582,7 @@ void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* } else out<<"(not container)" << endl; } +#endif } diff --git a/parser/htmlparser/src/nsDTDUtils.h b/parser/htmlparser/src/nsDTDUtils.h index e78ae89375a2..4ab22d90a4b7 100644 --- a/parser/htmlparser/src/nsDTDUtils.h +++ b/parser/htmlparser/src/nsDTDUtils.h @@ -34,7 +34,6 @@ #include "nsCRT.h" #include "nsDeque.h" #include "nsIDTD.h" -#include #include "nsITokenizer.h" #include "nsString.h" #include "nsIElementObserver.h" diff --git a/parser/htmlparser/src/nsElementTable.cpp b/parser/htmlparser/src/nsElementTable.cpp index 38dd5461496f..9a774f90dc59 100644 --- a/parser/htmlparser/src/nsElementTable.cpp +++ b/parser/htmlparser/src/nsElementTable.cpp @@ -477,7 +477,7 @@ nsHTMLElement gHTMLElements[] = { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0, - /*parent,incl,exclgroups*/ kBlock, kFlowEntity, kNone, + /*parent,incl,exclgroups*/ kBlock, kSelf|kFlowEntity, kNone, /*special props, prop-range*/ kOmitWS, kNoPropRange, /*special parents,kids,skip*/ 0,&gDLKids,eHTMLTag_unknown}, @@ -623,7 +623,7 @@ nsHTMLElement gHTMLElements[] = { /*rootnodes,endrootnodes*/ &gHTMLRootTags, &gHTMLRootTags, /*autoclose starttags and endtags*/ 0,0,0, /*parent,incl,exclgroups*/ kNone, kHTMLContent, kNone, - /*special props, prop-range*/ kOmitEndTag|kOmitWS|kNoStyleLeaksIn, kDefaultPropRange, + /*special props, prop-range*/ kSaveMisplaced|kOmitEndTag|kOmitWS|kNoStyleLeaksIn, kDefaultPropRange, /*special parents,kids,skip*/ 0,&gHtmlKids,eHTMLTag_unknown}, { /*tag*/ eHTMLTag_i, @@ -1712,6 +1712,7 @@ PRBool nsHTMLElement::HasSpecialProperty(PRInt32 aProperty) const{ } void nsHTMLElement::DebugDumpContainment(const char* aFilename,const char* aTitle){ +#ifdef RICKG_DEBUG PRBool t=CanContain(eHTMLTag_address,eHTMLTag_object); @@ -1761,9 +1762,12 @@ void nsHTMLElement::DebugDumpContainment(const char* aFilename,const char* aTitl linenum++; } } //for +#endif } void nsHTMLElement::DebugDumpMembership(const char* aFilename){ +#ifdef RICKG_DEBUG + const char* prefix=" "; const char* suffix=" "; const char* shortSuffix=" "; @@ -1815,10 +1819,13 @@ void nsHTMLElement::DebugDumpMembership(const char* aFilename){ out << answer[gHTMLElements[eHTMLTags(i)].mParentBits==kPreformatted] << suffix << endl; */ } //for - out< #include #include "nsString.h" #include "nsIParser.h" diff --git a/parser/htmlparser/src/nsHTMLNullSink.cpp b/parser/htmlparser/src/nsHTMLNullSink.cpp index 6a254080d7ec..baf70f3f9d0e 100644 --- a/parser/htmlparser/src/nsHTMLNullSink.cpp +++ b/parser/htmlparser/src/nsHTMLNullSink.cpp @@ -20,7 +20,6 @@ #include "nsHTMLTokens.h" #include "nsIParser.h" #include "prtypes.h" -#include #define VERBOSE_DEBUG diff --git a/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp index 72b882166ed3..53c61b0791cc 100644 --- a/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -29,7 +29,6 @@ #include "nsHTMLToTXTSinkStream.h" #include "nsHTMLTokens.h" -#include #include "nsString.h" #include "nsIParser.h" #include "nsHTMLEntities.h" diff --git a/parser/htmlparser/src/nsHTMLTokens.cpp b/parser/htmlparser/src/nsHTMLTokens.cpp index 70b119a1c15b..0225d4ade4fb 100644 --- a/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/parser/htmlparser/src/nsHTMLTokens.cpp @@ -820,13 +820,15 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) aString+=aChar; } - theRightChars.Truncate(0); - aString.Right(theRightChars,5); - theRightChars.StripChars(" "); + if(NS_OK==result){ + theRightChars.Truncate(0); + aString.Right(theRightChars,5); + theRightChars.StripChars(" "); - findpos=theRightChars.RFind("-->"); - if(kNotFound==findpos) - findpos=theRightChars.RFind("!>"); + findpos=theRightChars.RFind("-->"); + if(kNotFound==findpos) + findpos=theRightChars.RFind("!>"); + } } //while return result; } //if diff --git a/parser/htmlparser/src/nsHTMLTokens.h b/parser/htmlparser/src/nsHTMLTokens.h index 4e272bf14b00..ed93b4ffc892 100644 --- a/parser/htmlparser/src/nsHTMLTokens.h +++ b/parser/htmlparser/src/nsHTMLTokens.h @@ -42,7 +42,6 @@ #include "nsToken.h" #include "nsHTMLTags.h" #include "nsParserError.h" -#include #include "nsString.h" class nsScanner; diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index 9903a77ea6db..4e32b73bb747 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -25,7 +25,6 @@ #include "nsScanner.h" #include "prenv.h" //this is here for debug reasons... #include "plstr.h" -#include #include "nsIParserFilter.h" #include "nshtmlpars.h" #include "CNavDTD.h" @@ -711,13 +710,6 @@ nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled, void* aK */ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aVerifyEnabled,PRBool aLastCall){ -#ifdef _rickgdebug - { - fstream out("c:/temp/parseout.file",ios::trunc); - aSourceBuffer.DebugDump(out); - } -#endif - //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! @@ -1024,6 +1016,7 @@ nsParser::OnStatus(nsIURI* aURL, const PRUnichar* aMsg) } #ifdef rickgdebug +#include fstream* gDumpFile; #endif diff --git a/parser/htmlparser/src/nsToken.cpp b/parser/htmlparser/src/nsToken.cpp index 0c72ee21a59a..c2fbcd0d53fe 100644 --- a/parser/htmlparser/src/nsToken.cpp +++ b/parser/htmlparser/src/nsToken.cpp @@ -38,6 +38,8 @@ CToken::CToken(PRInt32 aTag) : mTextValue() { mTypeID=aTag; mAttrCount=0; TokenCount++; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** @@ -50,6 +52,8 @@ CToken::CToken(const nsString& aName) : mTextValue(aName) { mTypeID=0; mAttrCount=0; TokenCount++; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** @@ -62,6 +66,8 @@ CToken::CToken(const char* aName) : mTextValue(aName) { mTypeID=0; mAttrCount=0; TokenCount++; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** @@ -89,6 +95,8 @@ void CToken::Reinitialize(PRInt32 aTag, const nsString& aString){ mAttrCount=0; mTypeID=aTag; mAttrCount=0; + mOrigin=eSource; + mRecycle=PR_TRUE; } /** diff --git a/parser/htmlparser/src/nsToken.h b/parser/htmlparser/src/nsToken.h index a5c52724d562..1d83c44b821e 100644 --- a/parser/htmlparser/src/nsToken.h +++ b/parser/htmlparser/src/nsToken.h @@ -37,7 +37,6 @@ #include "prtypes.h" #include "nsString.h" -#include #include "nsError.h" class nsScanner; @@ -55,6 +54,8 @@ class nsScanner; class CToken { public: + enum eTokenOrigin {eSource,eResidualStyle}; + /** * Default constructor * @update gess7/21/98 @@ -195,6 +196,9 @@ class CToken { static int GetTokenCount(); + eTokenOrigin mOrigin; + PRBool mRecycle; + protected: PRInt32 mTypeID; PRInt16 mAttrCount; diff --git a/parser/htmlparser/src/nsXIFDTD.h b/parser/htmlparser/src/nsXIFDTD.h index 88fe58f94149..e5c46f9aafe9 100644 --- a/parser/htmlparser/src/nsXIFDTD.h +++ b/parser/htmlparser/src/nsXIFDTD.h @@ -35,7 +35,6 @@ #include "nsIContentSink.h" #include "nsHTMLTokens.h" #include "nsVoidArray.h" -#include #define NS_XIF_DTD_IID \