diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp
index 71c5d8895b3d..3f7c9eb205c4 100644
--- a/htmlparser/src/CNavDTD.cpp
+++ b/htmlparser/src/CNavDTD.cpp
@@ -695,10 +695,10 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
switch(theTag) {
case eHTMLTag_html:
- case eHTMLTag_comment:
case eHTMLTag_script:
case eHTMLTag_markupDecl:
break; // simply pass these through to token handler without further ado...
+ case eHTMLTag_comment:
case eHTMLTag_newline:
case eHTMLTag_whitespace:
if(mMisplacedContent.GetSize()<=0) // fix for bugs 17017,18308,23765, and 24275
@@ -1781,7 +1781,17 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
eHTMLTags theParentTag=mBodyContext->Last();
if(kNotFound==GetIndexOfChildOrSynonym(*mBodyContext,theChildTag)) {
- PopStyle(theChildTag);
+ // Ref: bug 30487
+ // Make sure that we don't cross boundaries, of certain elements,
+ // to close stylistic information.
+ // Ex.
some text...
+ // In the above ex. the orphaned FONT tag, inside TD, should cross TD boundaryto
+ // close the FONT tag above TABLE.
+ static eHTMLTags gBarriers[]={eHTMLTag_td,eHTMLTag_th};
+
+ if(!FindTagInSet(theParentTag,gBarriers,sizeof(gBarriers)/sizeof(theParentTag))) {
+ PopStyle(theChildTag);
+ }
// If the bit kHandleStrayTag is set then we automatically open up a matching
// start tag ( compatibility ). Currently this bit is set on P tag.
diff --git a/htmlparser/src/nsElementTable.cpp b/htmlparser/src/nsElementTable.cpp
index d12911ca54cd..30b62653b2cf 100644
--- a/htmlparser/src/nsElementTable.cpp
+++ b/htmlparser/src/nsElementTable.cpp
@@ -1953,23 +1953,34 @@ eHTMLTags nsHTMLElement::GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32
}
else if(IsResidualStyleTag(mTagID)){
+ // Ref. bug 37618
+ // Before finding a close target, for the current tag, make sure
+ // that the tag above does not gate.
+ // Ex.
+ // Here the /FONT inside OPTION should not close try to close FONT
+ // above SELECT. This would cause select to get closed!!!
+ eHTMLTags thePrevTag=(eHTMLTags)aContext.Last();
+
+ if(IsInlineParent(thePrevTag)) {
+
//we intentionally make 2 passes:
//The first pass tries to exactly match, the 2nd pass matches the group.
- PRInt32 theIndexCopy=theIndex;
- while(--theIndex>=anIndex){
- eHTMLTags theTag=aContext.TagAt(theIndex);
- if(theTag==mTagID) {
- return theTag;
+ PRInt32 theIndexCopy=theIndex;
+ while(--theIndex>=anIndex){
+ eHTMLTags theTag=aContext.TagAt(theIndex);
+ if(theTag==mTagID) {
+ return theTag;
+ }
+ }
+ theIndex=theIndexCopy;
+ while(--theIndex>=anIndex){
+ eHTMLTags theTag=aContext.TagAt(theIndex);
+ if(gHTMLElements[theTag].IsMemberOf(mParentBits)) {
+ return theTag;
+ }
}
}
- theIndex=theIndexCopy;
- while(--theIndex>=anIndex){
- eHTMLTags theTag=aContext.TagAt(theIndex);
- if(gHTMLElements[theTag].IsMemberOf(mParentBits)) {
- return theTag;
- }
- }
-
+
}
return result;
}
diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp
index 71c5d8895b3d..3f7c9eb205c4 100644
--- a/parser/htmlparser/src/CNavDTD.cpp
+++ b/parser/htmlparser/src/CNavDTD.cpp
@@ -695,10 +695,10 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
switch(theTag) {
case eHTMLTag_html:
- case eHTMLTag_comment:
case eHTMLTag_script:
case eHTMLTag_markupDecl:
break; // simply pass these through to token handler without further ado...
+ case eHTMLTag_comment:
case eHTMLTag_newline:
case eHTMLTag_whitespace:
if(mMisplacedContent.GetSize()<=0) // fix for bugs 17017,18308,23765, and 24275
@@ -1781,7 +1781,17 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
eHTMLTags theParentTag=mBodyContext->Last();
if(kNotFound==GetIndexOfChildOrSynonym(*mBodyContext,theChildTag)) {
- PopStyle(theChildTag);
+ // Ref: bug 30487
+ // Make sure that we don't cross boundaries, of certain elements,
+ // to close stylistic information.
+ // Ex.
some text...
+ // In the above ex. the orphaned FONT tag, inside TD, should cross TD boundaryto
+ // close the FONT tag above TABLE.
+ static eHTMLTags gBarriers[]={eHTMLTag_td,eHTMLTag_th};
+
+ if(!FindTagInSet(theParentTag,gBarriers,sizeof(gBarriers)/sizeof(theParentTag))) {
+ PopStyle(theChildTag);
+ }
// If the bit kHandleStrayTag is set then we automatically open up a matching
// start tag ( compatibility ). Currently this bit is set on P tag.
diff --git a/parser/htmlparser/src/nsElementTable.cpp b/parser/htmlparser/src/nsElementTable.cpp
index d12911ca54cd..30b62653b2cf 100644
--- a/parser/htmlparser/src/nsElementTable.cpp
+++ b/parser/htmlparser/src/nsElementTable.cpp
@@ -1953,23 +1953,34 @@ eHTMLTags nsHTMLElement::GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32
}
else if(IsResidualStyleTag(mTagID)){
+ // Ref. bug 37618
+ // Before finding a close target, for the current tag, make sure
+ // that the tag above does not gate.
+ // Ex.
+ // Here the /FONT inside OPTION should not close try to close FONT
+ // above SELECT. This would cause select to get closed!!!
+ eHTMLTags thePrevTag=(eHTMLTags)aContext.Last();
+
+ if(IsInlineParent(thePrevTag)) {
+
//we intentionally make 2 passes:
//The first pass tries to exactly match, the 2nd pass matches the group.
- PRInt32 theIndexCopy=theIndex;
- while(--theIndex>=anIndex){
- eHTMLTags theTag=aContext.TagAt(theIndex);
- if(theTag==mTagID) {
- return theTag;
+ PRInt32 theIndexCopy=theIndex;
+ while(--theIndex>=anIndex){
+ eHTMLTags theTag=aContext.TagAt(theIndex);
+ if(theTag==mTagID) {
+ return theTag;
+ }
+ }
+ theIndex=theIndexCopy;
+ while(--theIndex>=anIndex){
+ eHTMLTags theTag=aContext.TagAt(theIndex);
+ if(gHTMLElements[theTag].IsMemberOf(mParentBits)) {
+ return theTag;
+ }
}
}
- theIndex=theIndexCopy;
- while(--theIndex>=anIndex){
- eHTMLTags theTag=aContext.TagAt(theIndex);
- if(gHTMLElements[theTag].IsMemberOf(mParentBits)) {
- return theTag;
- }
- }
-
+
}
return result;
}