Fix infinite loop bug
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 27 Oct 2011 15:16:47 -0600
changeset 661 ecbd0e911073
parent 660 d4c00ae03638
child 662 420aa6a5998b
Fix infinite loop bug

Tests were run, no changes in output. I didn't add a new test that
actually works, because I'm not sure what the output should be (bug
filed).
editing.html
implementation.js
source.html
tests.js
--- a/editing.html	Thu Oct 27 15:15:06 2011 -0600
+++ b/editing.html	Thu Oct 27 15:16:47 2011 -0600
@@ -4575,14 +4575,12 @@
   <li>If <var title="">node</var> is not <a href=#editable>editable</a>, abort these steps.
 
   <li>
-  <p class=comments>The requirement about default containers is to prevent an
-  infinite loop.  This case is really intended to handle stuff like list items
-  or table cells that wander outside their proper place.
+  <p class=comments>This case is really intended to handle stuff like list
+  items or table cells that wander outside their proper place.  We generally
+  convert them into <code class=external data-anolis-spec=html title="the p element"><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping-content.html#the-p-element>p</a></code>s.
 
   <p>If <var title="">node</var> is not an <a href=#allowed-child>allowed child</a> of any of its
-  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestors</a> <a href=#in-the-same-editing-host>in the same editing host</a>, and is not an <a href=#html-element>HTML
-  element</a> with <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-element-local-name title=concept-element-local-name>local name</a> equal to the <a href=#default-single-line-container-name>default single-line
-  container name</a>:
+  <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestors</a> <a href=#in-the-same-editing-host>in the same editing host</a>:
 
   <ol>
     <li>If <var title="">node</var> is a <code class=external data-anolis-spec=html title="the dd element"><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping-content.html#the-dd-element>dd</a></code> or <code class=external data-anolis-spec=html title="the dt element"><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping-content.html#the-dt-element>dt</a></code>, <a href=#wrap>wrap</a> the
@@ -4592,6 +4590,13 @@
     result of calling <code class=external data-anolis-spec=dom title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("dl")</a></code> on the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a>.  Then
     abort these steps.
 
+    <li>
+    <p class=comments>There's no reason to change the node to a paragraph if
+    that won't make it an allowed child anyway.
+
+    <p>If "p" is not an <a href=#allowed-child>allowed child</a> of the <a href=#editing-host-of>editing host
+    of</a> <var title="">node</var>, abort these steps.
+
     <li>If <var title="">node</var> is not a <a href=#prohibited-paragraph-child>prohibited paragraph child</a>,
     abort these steps.
 
--- a/implementation.js	Thu Oct 27 15:15:06 2011 -0600
+++ b/implementation.js	Thu Oct 27 15:16:47 2011 -0600
@@ -3754,13 +3754,11 @@
 	}
 
 	// "If node is not an allowed child of any of its ancestors in the same
-	// editing host, and is not an HTML element with local name equal to the
-	// default single-line container name:"
+	// editing host:"
 	if (getAncestors(node).every(function(ancestor) {
 		return !inSameEditingHost(node, ancestor)
 			|| !isAllowedChild(node, ancestor)
-	})
-	&& !isHtmlElement(node, defaultSingleLineContainerName)) {
+	})) {
 		// "If node is a dd or dt, wrap the one-node list consisting of node,
 		// with sibling criteria returning true for any dl with no attributes
 		// and false otherwise, and new parent instructions returning the
@@ -3773,6 +3771,12 @@
 			return;
 		}
 
+		// "If "p" is not an allowed child of the editing host of node, abort
+		// these steps."
+		if (!isAllowedChild("p", getEditingHostOf(node))) {
+			return;
+		}
+
 		// "If node is not a prohibited paragraph child, abort these steps."
 		if (!isProhibitedParagraphChild(node)) {
 			return;
--- a/source.html	Thu Oct 27 15:15:06 2011 -0600
+++ b/source.html	Thu Oct 27 15:16:47 2011 -0600
@@ -4614,14 +4614,12 @@
   <li>If <var>node</var> is not <span>editable</span>, abort these steps.
 
   <li>
-  <p class=comments>The requirement about default containers is to prevent an
-  infinite loop.  This case is really intended to handle stuff like list items
-  or table cells that wander outside their proper place.
+  <p class=comments>This case is really intended to handle stuff like list
+  items or table cells that wander outside their proper place.  We generally
+  convert them into [[p]]s.
 
   <p>If <var>node</var> is not an <span>allowed child</span> of any of its
-  [[ancestors]] <span>in the same editing host</span>, and is not an <span>HTML
-  element</span> with [[localname]] equal to the <span>default single-line
-  container name</span>:
+  [[ancestors]] <span>in the same editing host</span>:
 
   <ol>
     <li>If <var>node</var> is a [[dd]] or [[dt]], <span>wrap</span> the
@@ -4631,6 +4629,13 @@
     result of calling [[createelement|"dl"]] on the [[contextobject]].  Then
     abort these steps.
 
+    <li>
+    <p class=comments>There's no reason to change the node to a paragraph if
+    that won't make it an allowed child anyway.
+
+    <p>If "p" is not an <span>allowed child</span> of the <span>editing host
+    of</span> <var>node</var>, abort these steps.
+
     <li>If <var>node</var> is not a <span>prohibited paragraph child</span>,
     abort these steps.
 
--- a/tests.js	Thu Oct 27 15:15:06 2011 -0600
+++ b/tests.js	Thu Oct 27 15:16:47 2011 -0600
@@ -2199,6 +2199,12 @@
 		'<ol><li>foo</ol> <p>[bar]',
 		'<p>[foo]</p> <ol><li>bar</ol>',
 		'<ol><li>foo</ol> <p>[bar]</p> <ol><li>baz</ol>',
+
+		// This caused an infinite loop at one point due to a bug in "fix
+		// disallowed ancestors".  Disabled because I'm not sure how we want it
+		// to behave:
+		// http://www.w3.org/Bugs/Public/show_bug.cgi?id=14578
+		'!<span contenteditable=true>foo[]</span>',
 	],
 	//@}
 	insertparagraph: [