<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19968</bug_id>
          
          <creation_ts>2012-11-15 12:50:32 +0000</creation_ts>
          <short_desc>splitText() can create ranges with end before start</short_desc>
          <delta_ts>2012-11-25 12:02:38 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Aryeh Gregor">ayg</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bugs</cc>
    
    <cc>matspal</cc>
    
    <cc>mike</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>78350</commentid>
    <comment_count>0</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-11-15 12:50:32 +0000</bug_when>
    <thetext>Test-case:

data:text/html,&lt;!doctype html&gt;
abcdef&lt;br&gt;
&lt;script&gt;
document.body.firstChild.splitText(3);
var range = document.createRange();
range.setStart(document.body.firstChild, 2);
range.setEnd(document.body, 1);
document.body.firstChild.splitText(1);
document.body.appendChild(document.createTextNode(
&quot;(&quot; + range.startContainer.nodeName + &quot; &quot; + range.startContainer.nodeValue
+ &quot;, &quot; + range.startOffset
+ &quot;) (&quot; + range.endContainer.nodeName + &quot; &quot; + range.endContainer.nodeValue
+ &quot;, &quot; + range.endOffset + &quot;)&quot;));
&lt;/script&gt;

Gecko and WebKit give &quot;(#text bc, 1) (BODY null, 1)&quot; -- where the node &quot;#text bc&quot; is the second child of &lt;body&gt;, so the end is before the start.  Opera gives &quot;(#text bc, 1) (#text bc, 1)&quot;, which makes no sense but at least isn&apos;t backwards.  IE gives &quot;(#text bc, 2) (BODY null, 1)&quot;, which is the most broken of all.  The spec requires Gecko/WebKit behavior, and is thus obviously wrong.

Mats Palmgren explains the problem in detail in this Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=803924#c19  He also gives a suggested fix, namely to have splitText() explicitly handle the case where a boundary point falls at the insertion point of the new node.  His fix looks good to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78391</commentid>
    <comment_count>1</comment_count>
    <who name="Mats Palmgren">matspal</who>
    <bug_when>2012-11-16 11:49:40 +0000</bug_when>
    <thetext>&gt; IE gives &quot;(#text bc, 2) (BODY null, 1)&quot;, which is the most
&gt; broken of all.

I think the latest IE has been fixed.
The result I get with the preview version(*) of IE10 for Windows 7 is:
(#text bc, 1) (BODY null, 2) 

(*) IE10.0.9200.16438 to be exact

Furthermore, the subset of tests in test_Range-mutations.html that failed
with my fix in 803924 also fails in that IE version:

splitTextTests.push(
        [&quot;paras[0].firstChild&quot;, 1, &quot;paras[0]&quot;, 0, &quot;paras[0]&quot;, 1],
        [&quot;paras[0].firstChild&quot;, 1, &quot;paras[0]&quot;, 1, &quot;paras[0]&quot;, 1],
        [&quot;paras[0].firstChild&quot;, 1, &quot;paras[0].firstChild&quot;, 1, &quot;paras[0]&quot;, 1],
        [&quot;paras[0].firstChild&quot;, 2, &quot;paras[0].firstChild&quot;, 1, &quot;paras[0]&quot;, 1],
        [&quot;paras[0].firstChild&quot;, 3, &quot;paras[0].firstChild&quot;, 1, &quot;paras[0]&quot;, 1],
        [&quot;paras[0].firstChild&quot;, 1, &quot;paras[0].firstChild&quot;, 2, &quot;paras[0]&quot;, 1]
);

After I fixed the testSplitText() function in test_Range-mutations.html
to implement the proposed spec change, both IE and my patched Firefox
pass those tests.

I think this strengthens the argument for changing the spec in the way
I propose, since two UA vendors have *independently* implemented the
same fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78419</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-16 19:24:50 +0000</bug_when>
    <thetext>https://github.com/whatwg/dom/commit/f1faaecd9881dd2f3654643eb89c46604c41ce73</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78776</commentid>
    <comment_count>3</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-11-25 12:02:38 +0000</bug_when>
    <thetext>Tests updated:

http://dvcs.w3.org/hg/webapps/rev/7250c98632b2

Firefox nightly now passes all of them again.  (The old nightlies passed the old tests, then Firefox was fixed and failed some of the tests, now the tests are fixed so it passes again.)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>