Bug 458145 - Don't allow random tags to close the body unexpectedly. r+sr=jst
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 03 Oct 2008 17:36:29 -0700
changeset 20077 0c1ec80708a16cf2c83c26e9f860f86234b330c0
parent 20076 5f519a29afec46c045931493a132e10a673924dc
child 20079 dc71e84d6cb62ef6101ea8f6d5ef0713f99671ad
push id2627
push usermrbkap@mozilla.com
push dateSat, 04 Oct 2008 01:08:06 +0000
treeherdermozilla-central@0c1ec80708a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs458145
milestone1.9.1b1pre
Bug 458145 - Don't allow random tags to close the body unexpectedly. r+sr=jst
parser/htmlparser/src/CNavDTD.cpp
parser/htmlparser/tests/mochitest/regressions.txt
--- a/parser/htmlparser/src/CNavDTD.cpp
+++ b/parser/htmlparser/src/CNavDTD.cpp
@@ -2269,17 +2269,17 @@ CNavDTD::CanOmit(eHTMLTags aParent, eHTM
   if (gHTMLElements[aParent].CanExclude(aChild)) {
     return PR_TRUE;
   }
 
   // Now the obvious test: if the parent can contain the child, don't omit.
   if (-1 == aParentContains) {
     aParentContains = CanContain(aParent, aChild);
   }
-  
+
   if (aParentContains || aChild == aParent) {
     return PR_FALSE;
   }
 
   if (gHTMLElements[aParent].IsBlockEntity() &&
       nsHTMLElement::IsInlineEntity(aChild)) {
     // Feel free to drop inlines that a block doesn't contain.
     return PR_TRUE;
@@ -2290,16 +2290,22 @@ CNavDTD::CanOmit(eHTMLTags aParent, eHTM
     // special property.
     return !gHTMLElements[aChild].HasSpecialProperty(kBadContentWatch);
   }
 
   if (gHTMLElements[aParent].HasSpecialProperty(kSaveMisplaced)) {
     return PR_TRUE;
   }
 
+  if (aParent == eHTMLTag_body) {
+    // There are very few tags that the body does not contain. If we get here
+    // the best thing to do is just drop them.
+    return PR_TRUE;
+  }
+
   return PR_FALSE;
 }
 
 /**
  *  This method gets called to determine whether a given 
  *  tag is itself a container
  *  
  *  @update  gess 4/8/98
--- a/parser/htmlparser/tests/mochitest/regressions.txt
+++ b/parser/htmlparser/tests/mochitest/regressions.txt
@@ -418,8 +418,17 @@ x { content:"</style" } "
 | <!DOCTYPE HTML>
 | <html>
 |   <head>
 |   <body>
 |     <form>
 |       <input>
 |         type=" hidden"
 
+#data
+<html><head><source>text<body><link>
+#errors
+#document
+| <html>
+|   <head>
+|   <body>
+|     "text"
+|     <link>