From 10435aa88c0732d1b82392fc537c599af5a24dc2 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Thu, 13 Aug 1998 08:33:18 +0000 Subject: [PATCH] a host of propagation bugs and a comment bug to boot --- htmlparser/src/CNavDTD.cpp | 168 ++++++++++++++----------- htmlparser/src/nsHTMLTokens.cpp | 24 ++-- parser/htmlparser/src/CNavDTD.cpp | 168 ++++++++++++++----------- parser/htmlparser/src/nsHTMLTokens.cpp | 24 ++-- 4 files changed, 218 insertions(+), 166 deletions(-) diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index b52aa73158e..ab03b81130f 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -1664,7 +1664,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { case eHTMLTag_tr: { static char okTags[]={eHTMLTag_td,eHTMLTag_th,0}; - result=PRBool(0!=strchr(okTags,aChild)); + result=PRBool(0!=strchr(okTags,aChild)); } break; @@ -1743,84 +1743,108 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const { PRBool result=PR_FALSE; //begin with some simple (and obvious) cases... - switch(aChild) { - - case eHTMLTag_userdefined: - case eHTMLTag_comment: - result=PR_TRUE; - break; - - case eHTMLTag_html: - case eHTMLTag_body: - result=HasOpenContainer(aChild); //don't bother if they're already open... - break; - - case eHTMLTag_button: case eHTMLTag_fieldset: - case eHTMLTag_input: case eHTMLTag_isindex: - case eHTMLTag_label: case eHTMLTag_legend: - case eHTMLTag_select: case eHTMLTag_textarea: - case eHTMLTag_option: - if(PR_FALSE==HasOpenContainer(eHTMLTag_form)) - result=PR_TRUE; - break; - - case eHTMLTag_newline: - case eHTMLTag_whitespace: - - switch(aParent) { - case eHTMLTag_html: case eHTMLTag_head: - case eHTMLTag_title: case eHTMLTag_map: - case eHTMLTag_tr: case eHTMLTag_table: - case eHTMLTag_thead: case eHTMLTag_tfoot: - case eHTMLTag_tbody: case eHTMLTag_col: - case eHTMLTag_colgroup: case eHTMLTag_unknown: - result=PR_TRUE; - default: - break; - } //switch - break; - - //this code prevents table container elements from - //opening unless a table is actually already opened. - case eHTMLTag_tr: case eHTMLTag_thead: - case eHTMLTag_tfoot: case eHTMLTag_tbody: - case eHTMLTag_td: case eHTMLTag_th: - case eHTMLTag_caption: - if(PR_FALSE==HasOpenContainer(eHTMLTag_table)) - result=PR_TRUE; - break; - - case eHTMLTag_entity: - switch(aParent) { - case eHTMLTag_tr: case eHTMLTag_table: - case eHTMLTag_thead: case eHTMLTag_tfoot: - case eHTMLTag_tbody: - result=PR_TRUE; - default: - break; - } //switch - break; - - case eHTMLTag_frame: - if(eHTMLTag_iframe==aParent) - result=PR_TRUE; - break; - + switch(aParent) { case eHTMLTag_table: + if(eHTMLTag_form==aChild) + result=PR_FALSE; + else result=PRBool(!strchr(gTableTags,aChild)); + break; - if(eParseMode_noquirks!=mParseMode) { - if(eHTMLTag_table==GetTopNode()) { + case eHTMLTag_tr: + switch(aChild) { + case eHTMLTag_td: + case eHTMLTag_th: + case eHTMLTag_form: + case eHTMLTag_tr: + result=PR_FALSE; + break; + default: result=PR_TRUE; - } - break; } - //otherwise, we intentionally fall through... + break; + + case eHTMLTag_unknown: + result=PR_FALSE; + break; default: - if(eHTMLTag_unknown==aParent) - result=PR_FALSE; + + //ok, since no parent claimed it, test based on the child... + switch(aChild) { + + case eHTMLTag_userdefined: + case eHTMLTag_comment: + result=PR_TRUE; + break; + + case eHTMLTag_html: + case eHTMLTag_body: + result=HasOpenContainer(aChild); //don't bother if they're already open... + break; + + case eHTMLTag_button: case eHTMLTag_fieldset: + case eHTMLTag_input: case eHTMLTag_isindex: + case eHTMLTag_label: case eHTMLTag_legend: + case eHTMLTag_select: case eHTMLTag_textarea: + case eHTMLTag_option: + if(PR_FALSE==HasOpenContainer(eHTMLTag_form)) + result=PR_TRUE; + break; + + case eHTMLTag_newline: + case eHTMLTag_whitespace: + + switch(aParent) { + case eHTMLTag_html: case eHTMLTag_head: + case eHTMLTag_title: case eHTMLTag_map: + case eHTMLTag_tr: case eHTMLTag_table: + case eHTMLTag_thead: case eHTMLTag_tfoot: + case eHTMLTag_tbody: case eHTMLTag_col: + case eHTMLTag_colgroup: case eHTMLTag_unknown: + result=PR_TRUE; + default: + break; + } //switch + break; + + //this code prevents table container elements from + //opening unless a table is actually already opened. + case eHTMLTag_tr: case eHTMLTag_thead: + case eHTMLTag_tfoot: case eHTMLTag_tbody: + case eHTMLTag_td: case eHTMLTag_th: + case eHTMLTag_caption: + if(PR_FALSE==HasOpenContainer(eHTMLTag_table)) + result=PR_TRUE; + break; + + case eHTMLTag_entity: + switch(aParent) { + case eHTMLTag_tr: case eHTMLTag_table: + case eHTMLTag_thead: case eHTMLTag_tfoot: + case eHTMLTag_tbody: + result=PR_TRUE; + default: + break; + } //switch + break; + + case eHTMLTag_frame: + if(eHTMLTag_iframe==aParent) + result=PR_TRUE; + break; + + default: + + static char kNonStylizedTabletags[]={eHTMLTag_table,eHTMLTag_tr,0}; + if(0!=strchr(gStyleTags,aChild)) { + if(0!=strchr(kNonStylizedTabletags,aParent)) + return PR_TRUE; + } + + break; + } //switch break; - } //switch + } return result; } diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp index a6fcf1cc5e9..eb9844afb73 100644 --- a/htmlparser/src/nsHTMLTokens.cpp +++ b/htmlparser/src/nsHTMLTokens.cpp @@ -474,21 +474,21 @@ CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) { * @param aScanner -- controller of underlying input source * @return error result */ -nsresult CCommentToken::Consume(PRUnichar, CScanner& aScanner) { +nsresult CCommentToken::Consume(PRUnichar aChar, CScanner& aScanner) { - PRUnichar ch,ch2; - nsresult result=NS_OK; + nsresult result=NS_OK; static nsAutoString terminals(">"); - aScanner.GetChar(ch); + aScanner.GetChar(aChar); mTextValue=" - mTextValue+="--"; + mTextValue+="-"; PRInt32 findpos=-1; while((findpos==kNotFound) && (NS_OK==result)) { result=aScanner.ReadUntil(mTextValue,terminals,PR_TRUE); @@ -496,11 +496,13 @@ nsresult CCommentToken::Consume(PRUnichar, CScanner& aScanner) { } } } - return result; } + + if(NS_OK==result) { //if you're here, we're consuming a "short-form" comment - mTextValue+=ch; - result=aScanner.ReadUntil(mTextValue,terminals,PR_TRUE); + mTextValue+=aChar; + result=aScanner.ReadUntil(mTextValue,terminals,PR_TRUE); + } return result; }; diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index b52aa73158e..ab03b81130f 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -1664,7 +1664,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { case eHTMLTag_tr: { static char okTags[]={eHTMLTag_td,eHTMLTag_th,0}; - result=PRBool(0!=strchr(okTags,aChild)); + result=PRBool(0!=strchr(okTags,aChild)); } break; @@ -1743,84 +1743,108 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const { PRBool result=PR_FALSE; //begin with some simple (and obvious) cases... - switch(aChild) { - - case eHTMLTag_userdefined: - case eHTMLTag_comment: - result=PR_TRUE; - break; - - case eHTMLTag_html: - case eHTMLTag_body: - result=HasOpenContainer(aChild); //don't bother if they're already open... - break; - - case eHTMLTag_button: case eHTMLTag_fieldset: - case eHTMLTag_input: case eHTMLTag_isindex: - case eHTMLTag_label: case eHTMLTag_legend: - case eHTMLTag_select: case eHTMLTag_textarea: - case eHTMLTag_option: - if(PR_FALSE==HasOpenContainer(eHTMLTag_form)) - result=PR_TRUE; - break; - - case eHTMLTag_newline: - case eHTMLTag_whitespace: - - switch(aParent) { - case eHTMLTag_html: case eHTMLTag_head: - case eHTMLTag_title: case eHTMLTag_map: - case eHTMLTag_tr: case eHTMLTag_table: - case eHTMLTag_thead: case eHTMLTag_tfoot: - case eHTMLTag_tbody: case eHTMLTag_col: - case eHTMLTag_colgroup: case eHTMLTag_unknown: - result=PR_TRUE; - default: - break; - } //switch - break; - - //this code prevents table container elements from - //opening unless a table is actually already opened. - case eHTMLTag_tr: case eHTMLTag_thead: - case eHTMLTag_tfoot: case eHTMLTag_tbody: - case eHTMLTag_td: case eHTMLTag_th: - case eHTMLTag_caption: - if(PR_FALSE==HasOpenContainer(eHTMLTag_table)) - result=PR_TRUE; - break; - - case eHTMLTag_entity: - switch(aParent) { - case eHTMLTag_tr: case eHTMLTag_table: - case eHTMLTag_thead: case eHTMLTag_tfoot: - case eHTMLTag_tbody: - result=PR_TRUE; - default: - break; - } //switch - break; - - case eHTMLTag_frame: - if(eHTMLTag_iframe==aParent) - result=PR_TRUE; - break; - + switch(aParent) { case eHTMLTag_table: + if(eHTMLTag_form==aChild) + result=PR_FALSE; + else result=PRBool(!strchr(gTableTags,aChild)); + break; - if(eParseMode_noquirks!=mParseMode) { - if(eHTMLTag_table==GetTopNode()) { + case eHTMLTag_tr: + switch(aChild) { + case eHTMLTag_td: + case eHTMLTag_th: + case eHTMLTag_form: + case eHTMLTag_tr: + result=PR_FALSE; + break; + default: result=PR_TRUE; - } - break; } - //otherwise, we intentionally fall through... + break; + + case eHTMLTag_unknown: + result=PR_FALSE; + break; default: - if(eHTMLTag_unknown==aParent) - result=PR_FALSE; + + //ok, since no parent claimed it, test based on the child... + switch(aChild) { + + case eHTMLTag_userdefined: + case eHTMLTag_comment: + result=PR_TRUE; + break; + + case eHTMLTag_html: + case eHTMLTag_body: + result=HasOpenContainer(aChild); //don't bother if they're already open... + break; + + case eHTMLTag_button: case eHTMLTag_fieldset: + case eHTMLTag_input: case eHTMLTag_isindex: + case eHTMLTag_label: case eHTMLTag_legend: + case eHTMLTag_select: case eHTMLTag_textarea: + case eHTMLTag_option: + if(PR_FALSE==HasOpenContainer(eHTMLTag_form)) + result=PR_TRUE; + break; + + case eHTMLTag_newline: + case eHTMLTag_whitespace: + + switch(aParent) { + case eHTMLTag_html: case eHTMLTag_head: + case eHTMLTag_title: case eHTMLTag_map: + case eHTMLTag_tr: case eHTMLTag_table: + case eHTMLTag_thead: case eHTMLTag_tfoot: + case eHTMLTag_tbody: case eHTMLTag_col: + case eHTMLTag_colgroup: case eHTMLTag_unknown: + result=PR_TRUE; + default: + break; + } //switch + break; + + //this code prevents table container elements from + //opening unless a table is actually already opened. + case eHTMLTag_tr: case eHTMLTag_thead: + case eHTMLTag_tfoot: case eHTMLTag_tbody: + case eHTMLTag_td: case eHTMLTag_th: + case eHTMLTag_caption: + if(PR_FALSE==HasOpenContainer(eHTMLTag_table)) + result=PR_TRUE; + break; + + case eHTMLTag_entity: + switch(aParent) { + case eHTMLTag_tr: case eHTMLTag_table: + case eHTMLTag_thead: case eHTMLTag_tfoot: + case eHTMLTag_tbody: + result=PR_TRUE; + default: + break; + } //switch + break; + + case eHTMLTag_frame: + if(eHTMLTag_iframe==aParent) + result=PR_TRUE; + break; + + default: + + static char kNonStylizedTabletags[]={eHTMLTag_table,eHTMLTag_tr,0}; + if(0!=strchr(gStyleTags,aChild)) { + if(0!=strchr(kNonStylizedTabletags,aParent)) + return PR_TRUE; + } + + break; + } //switch break; - } //switch + } return result; } diff --git a/parser/htmlparser/src/nsHTMLTokens.cpp b/parser/htmlparser/src/nsHTMLTokens.cpp index a6fcf1cc5e9..eb9844afb73 100644 --- a/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/parser/htmlparser/src/nsHTMLTokens.cpp @@ -474,21 +474,21 @@ CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) { * @param aScanner -- controller of underlying input source * @return error result */ -nsresult CCommentToken::Consume(PRUnichar, CScanner& aScanner) { +nsresult CCommentToken::Consume(PRUnichar aChar, CScanner& aScanner) { - PRUnichar ch,ch2; - nsresult result=NS_OK; + nsresult result=NS_OK; static nsAutoString terminals(">"); - aScanner.GetChar(ch); + aScanner.GetChar(aChar); mTextValue=" - mTextValue+="--"; + mTextValue+="-"; PRInt32 findpos=-1; while((findpos==kNotFound) && (NS_OK==result)) { result=aScanner.ReadUntil(mTextValue,terminals,PR_TRUE); @@ -496,11 +496,13 @@ nsresult CCommentToken::Consume(PRUnichar, CScanner& aScanner) { } } } - return result; } + + if(NS_OK==result) { //if you're here, we're consuming a "short-form" comment - mTextValue+=ch; - result=aScanner.ReadUntil(mTextValue,terminals,PR_TRUE); + mTextValue+=aChar; + result=aScanner.ReadUntil(mTextValue,terminals,PR_TRUE); + } return result; };