diff --git a/mozilla/layout/reftests/bugs/311366-unknown-block-1-ref.html b/mozilla/layout/reftests/bugs/311366-unknown-block-1-ref.html
new file mode 100644
index 00000000000..2bdd61718d8
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-block-1-ref.html
@@ -0,0 +1,5 @@
+
+
+
This should have a green background
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-block-1.html b/mozilla/layout/reftests/bugs/311366-unknown-block-1.html
new file mode 100644
index 00000000000..46b0cba832d
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-block-1.html
@@ -0,0 +1,5 @@
+
+
+This should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-block-2-ref.html b/mozilla/layout/reftests/bugs/311366-unknown-block-2-ref.html
new file mode 100644
index 00000000000..858a0bd4ae8
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-block-2-ref.html
@@ -0,0 +1,5 @@
+
+
+
foothis should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-block-2.html b/mozilla/layout/reftests/bugs/311366-unknown-block-2.html
new file mode 100644
index 00000000000..51920456b73
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-block-2.html
@@ -0,0 +1,5 @@
+
+
+
foothis should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-block-3-ref.html b/mozilla/layout/reftests/bugs/311366-unknown-block-3-ref.html
new file mode 100644
index 00000000000..965bb04a719
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-block-3-ref.html
@@ -0,0 +1,5 @@
+
+
+This should have a green background
foo
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-block-3.html b/mozilla/layout/reftests/bugs/311366-unknown-block-3.html
new file mode 100644
index 00000000000..26b1cfdbf33
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-block-3.html
@@ -0,0 +1,5 @@
+
+
+This should have a green background
foo
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-inline-1-ref.html b/mozilla/layout/reftests/bugs/311366-unknown-inline-1-ref.html
new file mode 100644
index 00000000000..0efd5b85768
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-inline-1-ref.html
@@ -0,0 +1,5 @@
+
+
+foo this should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-inline-1.html b/mozilla/layout/reftests/bugs/311366-unknown-inline-1.html
new file mode 100644
index 00000000000..1b503ac1b0e
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-inline-1.html
@@ -0,0 +1,5 @@
+
+
+foo this should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-inline-2-ref.html b/mozilla/layout/reftests/bugs/311366-unknown-inline-2-ref.html
new file mode 100644
index 00000000000..149025eb970
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-inline-2-ref.html
@@ -0,0 +1,5 @@
+
+
+foo this should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/311366-unknown-inline-2.html b/mozilla/layout/reftests/bugs/311366-unknown-inline-2.html
new file mode 100644
index 00000000000..5640710c886
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/311366-unknown-inline-2.html
@@ -0,0 +1,5 @@
+
+
+foo this should have a green background
\ No newline at end of file
diff --git a/mozilla/layout/reftests/bugs/reftest.list b/mozilla/layout/reftests/bugs/reftest.list
index 521a1c048ec..9f7a97c05ed 100644
--- a/mozilla/layout/reftests/bugs/reftest.list
+++ b/mozilla/layout/reftests/bugs/reftest.list
@@ -185,6 +185,11 @@ fails-if(MOZ_WIDGET_TOOLKIT!="cocoa") HTTP == 289480.html#top 289480-ref.html #
== 307102-4.html 307102-4-ref.html
== 308406-1.html 308406-1-ref.html
== 308406-2.html 308406-2-ref.html
+== 311366-unknown-inline-1.html 311366-unknown-inline-1-ref.html
+== 311366-unknown-block-1.html 311366-unknown-block-1-ref.html
+!= 311366-unknown-block-3.html 311366-unknown-block-3-ref.html
+== 311366-unknown-block-2.html 311366-unknown-block-2-ref.html
+== 311366-unknown-inline-2.html 311366-unknown-inline-2-ref.html
== 311822-1.html 311822-1-ref-a.html
== 311822-1.html 311822-1-ref-b.html
== 315620-1a.html 315620-1-ref.html
diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp
index eb173a79815..4dd8ea2dafa 100644
--- a/mozilla/parser/htmlparser/src/CNavDTD.cpp
+++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp
@@ -932,6 +932,9 @@ CNavDTD::HandleDefaultStartToken(CToken* aToken, eHTMLTags aChildTag,
do {
eHTMLTags theParentTag = mBodyContext->TagAt(--theIndex);
+ if (theParentTag == eHTMLTag_userdefined) {
+ continue;
+ }
// Figure out whether this is a hidden input inside a
// table/tbody/thead/tfoot/tr