From 4045b60295f67782df3a088b65b75a2eda61a5a1 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Fri, 9 Sep 2005 18:03:47 +0000 Subject: [PATCH] bug 272702: Remove skipped content. This simplifies the code handling so we won't be + // closing the wrong tag. + if (mBodyContext->Last() != eHTMLTag_script) { + // Except if we're here, then there's probably a stray script tag. + NS_ASSERTION(mBodyContext->LastOf(eHTMLTag_script) == kNotFound, + "Mishandling scripts in CNavDTD"); + break; + } + + mBodyContext->Pop(); + result = CloseContainer(eHTMLTag_script, theChildTag, PR_FALSE); + break; + default: { //now check to see if this token should be omitted, or @@ -2012,7 +1873,7 @@ nsresult CNavDTD::HandleSavedTokens(PRInt32 anIndex) { theToken=(CToken*)mMisplacedContent.PopFront(); if(theToken) { theTag = (eHTMLTags)theToken->GetTypeID(); - attrCount = (gHTMLElements[theTag].mSkipTarget)? 0:theToken->GetAttributeCount(); + attrCount = theToken->GetAttributeCount(); // Put back attributes, which once got popped out, into the tokenizer for(PRInt32 j=0;jSetCanInterrupt(PR_FALSE); - - MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::HandleScriptToken(), this=%p\n", this)); - START_TIMER(); - - return result; -} - - /** * This method gets called when an "instruction" token has been * encountered in the parse process. @@ -2266,15 +2102,11 @@ nsresult CNavDTD::CollectAttributes(nsIParserNode *aNode,eHTMLTags aTag,PRInt32 int attr=0; nsresult result=NS_OK; - int theAvailTokenCount=mTokenizer->GetCount() + mSkippedContent.GetSize(); + int theAvailTokenCount=mTokenizer->GetCount(); if(aCount<=theAvailTokenCount) { CToken* theToken=0; - eHTMLTags theSkipTarget=gHTMLElements[aTag].mSkipTarget; for(attr=0;attrPopToken(); + theToken=mTokenizer->PopToken(); if(theToken) { eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType()); if(theType!=eToken_attribute) { @@ -2313,55 +2145,6 @@ nsresult CNavDTD::CollectAttributes(nsIParserNode *aNode,eHTMLTags aTag,PRInt32 return result; } - -/** - * Causes the next skipped-content token (if any) to - * be consumed by this node. - * - * @update gess 4Sep2000 - * @param node to consume skipped-content - * @param holds the number of skipped content elements encountered - * @return Error condition. - */ -NS_IMETHODIMP -CNavDTD::CollectSkippedContent(PRInt32 aTag, nsAString& aContent, PRInt32 &aLineNo) { - - NS_ASSERTION(aTag >= eHTMLTag_unknown && aTag <= NS_HTML_TAG_MAX, "tag array out of bounds"); - - aContent.Truncate(); - - NS_ASSERTION(eHTMLTag_unknown != gHTMLElements[aTag].mSkipTarget, "cannot collect content for this tag"); - if (eHTMLTag_unknown == gHTMLElements[aTag].mSkipTarget) { - // This tag doesn't support skipped content. - aLineNo = -1; - return NS_OK; - } - - aLineNo = mLineNumber; - mScratch.Truncate(); - PRInt32 i = 0; - PRInt32 tagCount = mSkippedContent.GetSize(); - for (i = 0; i< tagCount; ++i){ - CHTMLToken* theNextToken = (CHTMLToken*)mSkippedContent.PopFront(); - if (theNextToken) { - theNextToken->AppendSourceTo(aContent); - } - - IF_FREE(theNextToken, mTokenAllocator); - } - - InPlaceConvertLineEndings(aContent); - - // Note: TITLE content is PCDATA and hence the newlines are already accounted for. - mLineNumber += (aTag != eHTMLTag_title) ? aContent.CountChar(kNewLine) : 0; - - return NS_OK; -} - - /*********************************************************************************** - The preceeding tables determine the set of elements each tag can contain... - ***********************************************************************************/ - /** * This method is called to determine whether or not a tag * of one type can contain a tag of another type. @@ -2908,7 +2691,12 @@ nsresult CNavDTD::OpenHead(const nsIParserNode *aNode) if (!(mFlags & NS_DTD_FLAG_HAS_OPEN_HEAD)) { mFlags |= NS_DTD_FLAG_HAS_OPEN_HEAD; - result = mSink ? mSink->OpenHead(*aNode) : NS_OK; + if (mSink && aNode) { + result = mSink->OpenHead(*aNode); + } + else if (mSink) { + result = mSink->OpenHead(); + } } MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::OpenHead(), this=%p\n", this)); @@ -2965,6 +2753,10 @@ nsresult CNavDTD::OpenBody(const nsCParserNode *aNode) STOP_TIMER(); MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::OpenBody(), this=%p\n", this)); + // Make sure the head is closed by the time the body is opened. + CloseHead(); + + // Now we can open the body. result = (mSink) ? mSink->OpenBody(*aNode) : NS_OK; MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::OpenBody(), this=%p\n", this)); @@ -3205,10 +2997,6 @@ CNavDTD::OpenContainer(const nsCParserNode *aNode, } break; - case eHTMLTag_style: - case eHTMLTag_title: - break; - case eHTMLTag_map: result = OpenMap(aNode); break; @@ -3221,10 +3009,6 @@ CNavDTD::OpenContainer(const nsCParserNode *aNode, result = OpenFrameset(aNode); break; - case eHTMLTag_script: - result = HandleScriptToken(aNode); - break; - case eHTMLTag_noembed: // is unconditionally alternate content. done = PR_FALSE; @@ -3292,9 +3076,6 @@ CNavDTD::CloseContainer(const eHTMLTags aTag, eHTMLTags aTarget,PRBool aClosedBy case eHTMLTag_html: result=CloseHTML(); break; - case eHTMLTag_style: - break; - case eHTMLTag_head: result=CloseHead(); break; @@ -3322,12 +3103,22 @@ CNavDTD::CloseContainer(const eHTMLTags aTag, eHTMLTags aTarget,PRBool aClosedBy // switch from alternate content state to regular state mFlags &= ~NS_DTD_FLAG_ALTERNATE_CONTENT; // falling thro' intentionally.... - case eHTMLTag_title: default: STOP_TIMER(); MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseContainer(), this=%p\n", this)); - result=(mSink) ? mSink->CloseContainer(aTag) : NS_OK; + result = mSink + ? mSink->CloseContainer(aTag) + : NS_OK; // XXX Can this case really happen? + + // If we were dealing with a head container in the body, make sure to + // close the head context now, so that body content doesn't get sucked + // into the head. + if ((mFlags & NS_DTD_FLAG_HAD_BODY) && + mBodyContext->GetCount() == mHeadContainerPosition) { + result = CloseHead(); + mHeadContainerPosition = -1; + } MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseContainer(), this=%p\n", this)); START_TIMER(); @@ -3586,7 +3377,7 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode *aNode){ * @param aNode -- next node to be added to model * @return error code; 0 means OK */ -nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){ +nsresult CNavDTD::AddHeadContent(nsIParserNode *aNode){ nsresult result=NS_OK; static eHTMLTags gNoXTags[] = {eHTMLTag_noembed,eHTMLTag_noframes}; @@ -3604,11 +3395,35 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){ if (mSink) { STOP_TIMER(); - MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this)); - - result = mSink->AddHeadContent(*aNode); - - MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this)); + MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadContent(), this=%p\n", this)); + + // Make sure the head is opened. This might just be a no-op. + result = OpenHead(nsnull); + + // Note: userdefined tags in the head are treated as leaves. + if (!nsHTMLElement::IsContainer(theTag) || theTag == eHTMLTag_userdefined) { + result = mSink->AddLeaf(*aNode); + + if (mFlags & NS_DTD_FLAG_HAD_BODY) { + // Close the head now so that body content doesn't get sucked into it. + CloseHead(); + } + } + else { + if ((mFlags & NS_DTD_FLAG_HAD_BODY) && mHeadContainerPosition == -1) { + // Keep track of this so that we know when to close the head, when + // this tag is done with. + mHeadContainerPosition = mBodyContext->GetCount(); + } + + mBodyContext->Push(NS_STATIC_CAST(nsCParserNode*, aNode), nsnull, + PR_FALSE); + + // Note: The head context is already opened. + result = mSink->OpenContainer(*aNode); + } + + MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadContent(), this=%p\n", this)); START_TIMER(); } return result; diff --git a/mozilla/parser/htmlparser/src/CNavDTD.h b/mozilla/parser/htmlparser/src/CNavDTD.h index e8ce0910490..dfbb6e6e5aa 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.h +++ b/mozilla/parser/htmlparser/src/CNavDTD.h @@ -1,4 +1,5 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set sw=2 ts=2 et tw=78: */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -271,7 +272,6 @@ public: nsresult HandleEntityToken(CToken* aToken); nsresult HandleCommentToken(CToken* aToken); nsresult HandleAttributeToken(CToken* aToken); - nsresult HandleScriptToken(const nsIParserNode *aNode); nsresult HandleProcessingInstructionToken(CToken* aToken); nsresult HandleDocTypeDeclToken(CToken* aToken); nsresult BuildNeglectedTarget(eHTMLTags aTarget, eHTMLTokenTypes aType, @@ -337,7 +337,7 @@ public: * @return error code - 0 if all went well. */ nsresult AddLeaf(const nsIParserNode *aNode); - nsresult AddHeadLeaf(nsIParserNode *aNode); + nsresult AddHeadContent(nsIParserNode *aNode); /** * This set of methods is used to create and manage the set of @@ -365,7 +365,6 @@ public: protected: nsresult CollectAttributes(nsIParserNode* aNode,eHTMLTags aTag,PRInt32 aCount); - nsresult CollectSkippedContent(nsIParserNode& aNode,PRInt32& aCount); nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode); nsresult DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag); nsresult HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode *aNode); @@ -376,7 +375,6 @@ protected: PRBool IsInlineElement(PRInt32 aTagID, PRInt32 aParentID) const; nsDeque mMisplacedContent; - nsDeque mSkippedContent; nsIHTMLContentSink* mSink; nsTokenAllocator* mTokenAllocator; @@ -394,9 +392,9 @@ protected: eParserDocType mDocType; eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors... - eHTMLTags mSkipTarget; PRInt32 mLineNumber; PRInt32 mOpenMapCount; + PRInt32 mHeadContainerPosition; PRUint16 mFlags; }; diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp index 38f2b32132d..91f2eb56d95 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp @@ -291,6 +291,9 @@ nsCParserNode* nsEntryStack::Pop(void) // XXX If this NS_ENSURE_TRUE fails, it means that the style stack was // empty before we were removed. +#ifdef DEBUG_mrbkap + NS_ASSERTION(scount != 0, "preventing a potential crash."); +#endif NS_ENSURE_TRUE(scount != 0, result); PRUint32 sindex = 0; diff --git a/mozilla/parser/htmlparser/src/nsElementTable.cpp b/mozilla/parser/htmlparser/src/nsElementTable.cpp index f99a93a33fd..2be8259e41a 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.cpp +++ b/mozilla/parser/htmlparser/src/nsElementTable.cpp @@ -194,12 +194,6 @@ const nsHTMLElement gHTMLElements[] = { /*contain-func*/ 0 }, { - /************************************************* - Note: I changed A to contain flow elements - since it's such a popular (but illegal) - idiom. - *************************************************/ - /*tag*/ eHTMLTag_a, /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, @@ -905,7 +899,7 @@ const nsHTMLElement gHTMLElements[] = { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kFlowEntity|kInlineEntity|kSelf), kNone, // XXX should have a kHeadMisc parent too + /*parent,incl,exclgroups*/ kSpecial|kHeadMisc, (kFlowEntity|kSelf), kNone, /*special props, prop-range*/ kNoStyleLeaksOut,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gContainsParam,eHTMLTag_unknown, /*contain-func*/ 0 @@ -1017,7 +1011,7 @@ const nsHTMLElement gHTMLElements[] = { /*autoclose starttags and endtags*/ 0,0,0,0, /*parent,incl,exclgroups*/ (kSpecial|kHeadContent), kCDATA, kNone, // note: this is kHeadContent since shipping this breaks things. /*special props, prop-range*/ kNoStyleLeaksIn|kLegalOpen, kNoPropRange, - /*special parents,kids,skip*/ 0,&gContainsText,eHTMLTag_script, + /*special parents,kids,skip*/ 0,&gContainsText,eHTMLTag_unknown, /*contain-func*/ 0 }, { @@ -1037,7 +1031,7 @@ const nsHTMLElement gHTMLElements[] = { /*autoclose starttags and endtags*/ 0,0,0,0, /*parent,incl,exclgroups*/ (kSpecial|kHeadMisc), kCDATA, kNone, /*special props, prop-range*/ (kNoStyleLeaksIn|kLegalOpen), kNoPropRange, - /*special parents,kids,skip*/ 0,&gContainsText,eHTMLTag_server, + /*special parents,kids,skip*/ 0,&gContainsText,eHTMLTag_unknown, /*contain-func*/ 0 }, { @@ -1115,8 +1109,8 @@ const nsHTMLElement gHTMLElements[] = { /*rootnodes,endrootnodes*/ &gInHead,&gInHead, /*autoclose starttags and endtags*/ 0,0,0,0, /*parent,incl,exclgroups*/ kHeadContent, kCDATA, kNone, - /*special props, prop-range*/ kNoStyleLeaksIn|kNonContainer, kNoPropRange, - /*special parents,kids,skip*/ &gInHead,0,eHTMLTag_style, + /*special props, prop-range*/ kNoStyleLeaksIn, kNoPropRange, + /*special parents,kids,skip*/ &gInHead,0,eHTMLTag_unknown, /*contain-func*/ 0 }, { @@ -1217,7 +1211,7 @@ const nsHTMLElement gHTMLElements[] = { /*autoclose starttags and endtags*/ 0,0,0,0, /*parent,incl,exclgroups*/ kHeadContent,kPCDATA, kNone, /*special props, prop-range*/ kNoStyleLeaksIn, kNoPropRange, - /*special parents,kids,skip*/ &gInHead,&gContainsText,eHTMLTag_title, + /*special parents,kids,skip*/ &gInHead,&gContainsText,eHTMLTag_unknown, /*contain-func*/ 0 }, { diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index 99e184df46e..5b158f09a84 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -1155,13 +1155,6 @@ nsExpatDriver::GetType() /*************************** Unused methods **********************************/ -NS_IMETHODIMP -nsExpatDriver::CollectSkippedContent(PRInt32 aTag, nsAString& aContent, - PRInt32 &aLineNo) -{ - return NS_OK; -} - NS_IMETHODIMP_(CToken*) nsExpatDriver::PushTokenFront(CToken* aToken) { diff --git a/mozilla/parser/htmlparser/src/nsLoggingSink.cpp b/mozilla/parser/htmlparser/src/nsLoggingSink.cpp index a610e78ef7b..4b3ba0e4726 100644 --- a/mozilla/parser/htmlparser/src/nsLoggingSink.cpp +++ b/mozilla/parser/htmlparser/src/nsLoggingSink.cpp @@ -1,4 +1,5 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=2 et tw=78: */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -47,16 +48,6 @@ static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID); static NS_DEFINE_IID(kILoggingSinkIID, NS_ILOGGING_SINK_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -// list of tags that have skipped content -static const char gSkippedContentTags[] = { - eHTMLTag_style, - eHTMLTag_script, - eHTMLTag_server, - eHTMLTag_title, - 0 -}; - - nsresult NS_NewHTMLLoggingSink(nsIContentSink** aInstancePtrResult) { @@ -73,7 +64,7 @@ NS_NewHTMLLoggingSink(nsIContentSink** aInstancePtrResult) nsLoggingSink::nsLoggingSink() { mOutput = 0; - mLevel=-1; + mLevel=-1; mSink=0; mParser=0; } @@ -244,36 +235,6 @@ nsLoggingSink::CloseContainer(const nsHTMLTag aTag) { } -NS_IMETHODIMP -nsLoggingSink::AddHeadContent(const nsIParserNode& aNode) { - eHTMLTags type = (eHTMLTags)aNode.GetNodeType(); - - if (type == eHTMLTag_title) { - nsCOMPtr<nsIDTD> dtd; - mParser->GetDTD(getter_AddRefs(dtd)); - NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE); - - nsString theString; - PRInt32 lineNo = 0; - - dtd->CollectSkippedContent(type, theString, lineNo); - SetTitle(theString); - } - else { - LeafNode(aNode); - } - - nsresult theResult=NS_OK; - - //then proxy the call to the real sink if you have one. - if(mSink) { - theResult=mSink->AddHeadContent(aNode); - } - - return theResult; - -} - NS_IMETHODIMP nsLoggingSink::AddLeaf(const nsIParserNode& aNode) { LeafNode(aNode); @@ -365,31 +326,6 @@ nsLoggingSink::AddComment(const nsIParserNode& aNode){ } - -NS_IMETHODIMP -nsLoggingSink::SetTitle(const nsString& aValue) { - - char* tmp = nsnull; - GetNewCString(aValue, &tmp); - WriteTabs(mOutput,++mLevel); - if(tmp) { - PR_fprintf(mOutput, "<title value=\"%s\"/>\n", tmp); - nsMemory::Free(tmp); - } - --mLevel; - - nsresult theResult=NS_OK; - - //then proxy the call to the real sink if you have one. - if(mSink) { - theResult=mSink->SetTitle(aValue); - } - - return theResult; - -} - - NS_IMETHODIMP nsLoggingSink::OpenHTML(const nsIParserNode& aNode) { OpenNode("html", aNode); @@ -434,6 +370,21 @@ nsLoggingSink::OpenHead(const nsIParserNode& aNode) { return theResult; } +NS_IMETHODIMP +nsLoggingSink::OpenHead() { + WriteTabs(mOutput,++mLevel); + PR_fprintf(mOutput,"<open container=head>\n"); + + nsresult theResult=NS_OK; + + //then proxy the call to the real sink if you have one. + if(mSink) { + theResult=mSink->OpenHead(); + } + + return theResult; +} + NS_IMETHODIMP nsLoggingSink::CloseHead() { CloseNode("head"); @@ -645,23 +596,6 @@ nsLoggingSink::WriteAttributes(const nsIParserNode& aNode) { } } - if (0 != strchr(gSkippedContentTags, aNode.GetNodeType())) { - nsCOMPtr<nsIDTD> dtd; - mParser->GetDTD(getter_AddRefs(dtd)); - NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE); - - nsString theString; - PRInt32 lineNo = 0; - - dtd->CollectSkippedContent(aNode.GetNodeType(), theString, lineNo); - char* content = nsnull; - GetNewCString(theString, &content); - if(content) { - PR_fprintf(mOutput, " <content value=\""); - PR_fprintf(mOutput, "%s\"/>\n", content) ; - nsMemory::Free(content); - } - } WriteTabs(mOutput,1+mLevel); return NS_OK; } @@ -673,43 +607,31 @@ nsLoggingSink::WillWriteAttributes(const nsIParserNode& aNode) if (0 != ac) { return PR_TRUE; } - if (0 != strchr(gSkippedContentTags, aNode.GetNodeType())) { - nsCOMPtr<nsIDTD> dtd; - mParser->GetDTD(getter_AddRefs(dtd)); - NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE); - - nsString content; - PRInt32 lineNo = 0; - - dtd->CollectSkippedContent(aNode.GetNodeType(), content, lineNo); - if (!content.IsEmpty()) { - return PR_TRUE; - } - } return PR_FALSE; } nsresult nsLoggingSink::LeafNode(const nsIParserNode& aNode) { - WriteTabs(mOutput,1+mLevel); - nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); + WriteTabs(mOutput,1+mLevel); + nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); if ((nodeType >= eHTMLTag_unknown) && (nodeType <= nsHTMLTag(NS_HTML_TAG_MAX))) { const PRUnichar* tag = nsHTMLTags::GetStringValue(nodeType); - if(tag) + if(tag) PR_fprintf(mOutput, "<leaf tag=\"%s\"", NS_ConvertUCS2toUTF8(tag).get()); - else PR_fprintf(mOutput, "<leaf tag=\"???\""); + else + PR_fprintf(mOutput, "<leaf tag=\"???\""); if (WillWriteAttributes(aNode)) { - PR_fprintf(mOutput, ">\n"); + PR_fprintf(mOutput, ">\n"); WriteAttributes(aNode); - PR_fprintf(mOutput, "</leaf>\n"); + PR_fprintf(mOutput, "</leaf>\n"); } else { - PR_fprintf(mOutput, "/>\n"); + PR_fprintf(mOutput, "/>\n"); } } else { @@ -717,32 +639,32 @@ nsLoggingSink::LeafNode(const nsIParserNode& aNode) nsAutoString tmp; char* str = nsnull; switch (nodeType) { - case eHTMLTag_whitespace: - case eHTMLTag_text: - GetNewCString(aNode.GetText(), &str); - if(str) { - PR_fprintf(mOutput, "<text value=\"%s\"/>\n", str); - nsMemory::Free(str); - } - break; + case eHTMLTag_whitespace: + case eHTMLTag_text: + GetNewCString(aNode.GetText(), &str); + if(str) { + PR_fprintf(mOutput, "<text value=\"%s\"/>\n", str); + nsMemory::Free(str); + } + break; - case eHTMLTag_newline: - PR_fprintf(mOutput, "<newline/>\n"); - break; + case eHTMLTag_newline: + PR_fprintf(mOutput, "<newline/>\n"); + break; - case eHTMLTag_entity: - tmp.Append(aNode.GetText()); - tmp.Cut(0, 1); - pos = tmp.Length() - 1; - if (pos >= 0) { - tmp.Cut(pos, 1); - } - PR_fprintf(mOutput, "<entity value=\"%s\"/>\n", NS_LossyConvertUCS2toASCII(tmp).get()); - break; + case eHTMLTag_entity: + tmp.Append(aNode.GetText()); + tmp.Cut(0, 1); + pos = tmp.Length() - 1; + if (pos >= 0) { + tmp.Cut(pos, 1); + } + PR_fprintf(mOutput, "<entity value=\"%s\"/>\n", NS_LossyConvertUCS2toASCII(tmp).get()); + break; - default: - NS_NOTREACHED("unsupported leaf node type"); - }//switch + default: + NS_NOTREACHED("unsupported leaf node type"); + }//switch } return NS_OK; } diff --git a/mozilla/parser/htmlparser/src/nsLoggingSink.h b/mozilla/parser/htmlparser/src/nsLoggingSink.h index 969ae8a8af7..c252da699c0 100644 --- a/mozilla/parser/htmlparser/src/nsLoggingSink.h +++ b/mozilla/parser/htmlparser/src/nsLoggingSink.h @@ -67,7 +67,6 @@ public: NS_IMETHOD SetParser(nsIParser* aParser); NS_IMETHOD OpenContainer(const nsIParserNode& aNode); NS_IMETHOD CloseContainer(const nsHTMLTag aTag); - NS_IMETHOD AddHeadContent(const nsIParserNode& aNode); NS_IMETHOD AddLeaf(const nsIParserNode& aNode); NS_IMETHOD AddComment(const nsIParserNode& aNode); NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode); @@ -77,10 +76,10 @@ public: virtual nsISupports *GetTarget() { return nsnull; } // nsIHTMLContentSink - NS_IMETHOD SetTitle(const nsString& aValue); NS_IMETHOD OpenHTML(const nsIParserNode& aNode); NS_IMETHOD CloseHTML(); NS_IMETHOD OpenHead(const nsIParserNode& aNode); + NS_IMETHOD OpenHead(); NS_IMETHOD CloseHead(); NS_IMETHOD OpenBody(const nsIParserNode& aNode); NS_IMETHOD CloseBody(); @@ -116,10 +115,10 @@ public: protected: PRFileDesc *mOutput; - int mLevel; + int mLevel; nsIHTMLContentSink *mSink; - PRBool mAutoDeleteOutput; - nsIParser* mParser; + PRBool mAutoDeleteOutput; + nsIParser* mParser; }; #endif diff --git a/mozilla/parser/htmlparser/tests/html/TestParser.cpp b/mozilla/parser/htmlparser/tests/html/TestParser.cpp index a849222eb1a..1620c9eb547 100644 --- a/mozilla/parser/htmlparser/tests/html/TestParser.cpp +++ b/mozilla/parser/htmlparser/tests/html/TestParser.cpp @@ -74,13 +74,14 @@ nsresult ParseData(char* anInputStream,char* anOutputStream) { return result; } - PRFileDesc* in = PR_Open(anInputStream, PR_RDONLY, 777); + PRFileDesc* in = PR_Open(anInputStream, PR_RDONLY, 0777); if (!in) { printf("\nUnable to open input file - %s\n", anInputStream); return result; } - PRFileDesc* out = PR_Open(anOutputStream, PR_CREATE_FILE|PR_WRONLY, 777); + PRFileDesc* out = PR_Open(anOutputStream, + PR_CREATE_FILE|PR_TRUNCATE|PR_RDWR, 0777); if (!out) { printf("\nUnable to open output file - %s\n", anOutputStream); return result;