Avoid unserializable DOMs with <hr>
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Wed, 25 May 2011 13:35:50 -0600
changeset 175 2e26a8cbfab2
parent 174 8c7fc90f9d2f
child 176 7776444f1926
Avoid unserializable DOMs with <hr>
autoimplementation.html
editcommands.html
implementation.js
source.html
--- a/autoimplementation.html	Wed May 25 13:24:14 2011 -0600
+++ b/autoimplementation.html	Wed May 25 13:35:50 2011 -0600
@@ -853,6 +853,7 @@
 		'foo[]bar',
 		'<span>foo</span>{}<span>bar</span>',
 		'<span>foo[</span><span>]bar</span>',
+		'<p>foo[bar<p>baz]quz',
 		'<div><b>foo</b>{}<b>bar</b></div>',
 		'<div><b>foo[</b><b>]bar</b></div>',
 		'<div><b>foo</b>{<b>bar</b>}<b>baz</b></div>',
@@ -862,7 +863,9 @@
 		'foo[bar]baz',
 		'foo<b>{bar}</b>baz',
 		'<p>foo[bar]baz</p>',
-		'<p>foo[bar<p>baz]quz',
+		'<p id=abc>foo[bar]baz</p>',
+		'<h1>foo[bar]baz</h1>',
+		'<p>foo<b>b[a]r</b>baz</p>',
 	],
 	insertimage: [
 		'foo[]bar',
--- a/editcommands.html	Wed May 25 13:24:14 2011 -0600
+++ b/editcommands.html	Wed May 25 13:35:50 2011 -0600
@@ -3887,12 +3887,18 @@
 
   <li>Run <code class=external data-anolis-spec=domrange title=dom-Range-insertNode><a href=http://html5.org/specs/dom-range.html#dom-range-insertnode>insertNode(<var title="">hr</var>)</a></code> on
   <var title="">range</var>.
-  <!-- This might put it in an inline element, where it's invalid.  This is
-  what IE9 and Chrome 12 dev appear to do.  Firefox 4.0 breaks up inline
-  ancestors, and Opera 11.10 seems to put it before the first inline ancestor
-  instead of where the cursor is.  Breaking up elements is kind of evil, so
-  I'll go with IE/WebKit.  Even though it produces invalid markup, it does
-  still work. -->
+
+  <li><a href=#fix-disallowed-ancestors>Fix disallowed ancestors</a> of <var title="">hr</var>.
+  <!--
+  IE9 seems to be acting flaky and I can't get it to work here, so I didn't try
+  testing it here.  Firefox 5.0a2 breaks up any ancestors that can contain only
+  phrasing content, like <b> and so on.  Chrome 13 dev doesn't bother fixing
+  ancestors at all, which can lead to unserializable DOMs like <hr> inside <p>.
+  Opera 11.10 acts very weirdly, sometimes mysteriously sticking the <hr>
+  before some ancestor, sometimes breaking up ancestors like <div> totally
+  unnecessarily.  None of these match the "fix disallowed ancestors" rules at
+  the time of this writing.
+  -->
 
   <li>Let <var title="">selection</var> be the result of running <code class=external data-anolis-spec=domrange title=dom-Document-getSelection><a href=http://html5.org/specs/dom-range.html#dom-document-getselection>getSelection()</a></code> on the
   <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#context-object>context object</a>.
--- a/implementation.js	Wed May 25 13:24:14 2011 -0600
+++ b/implementation.js	Wed May 25 13:35:50 2011 -0600
@@ -2918,6 +2918,9 @@
 		// "Run insertNode(hr) on the range."
 		range.insertNode(hr);
 
+		// "Fix disallowed ancestors of hr."
+		fixDisallowedAncestors(hr);
+
 		// "Run collapse() on the Selection, with first argument equal to the
 		// parent of hr and the second argument equal to one plus the index of
 		// hr."
--- a/source.html	Wed May 25 13:24:14 2011 -0600
+++ b/source.html	Wed May 25 13:35:50 2011 -0600
@@ -3916,12 +3916,18 @@
   <li>Run <code data-anolis-spec=domrange
   title=dom-Range-insertNode>insertNode(<var>hr</var>)</code> on
   <var>range</var>.
-  <!-- This might put it in an inline element, where it's invalid.  This is
-  what IE9 and Chrome 12 dev appear to do.  Firefox 4.0 breaks up inline
-  ancestors, and Opera 11.10 seems to put it before the first inline ancestor
-  instead of where the cursor is.  Breaking up elements is kind of evil, so
-  I'll go with IE/WebKit.  Even though it produces invalid markup, it does
-  still work. -->
+
+  <li><span>Fix disallowed ancestors</span> of <var>hr</var>.
+  <!--
+  IE9 seems to be acting flaky and I can't get it to work here, so I didn't try
+  testing it here.  Firefox 5.0a2 breaks up any ancestors that can contain only
+  phrasing content, like <b> and so on.  Chrome 13 dev doesn't bother fixing
+  ancestors at all, which can lead to unserializable DOMs like <hr> inside <p>.
+  Opera 11.10 acts very weirdly, sometimes mysteriously sticking the <hr>
+  before some ancestor, sometimes breaking up ancestors like <div> totally
+  unnecessarily.  None of these match the "fix disallowed ancestors" rules at
+  the time of this writing.
+  -->
 
   <li>Let <var>selection</var> be the result of running <code
   data-anolis-spec=domrange