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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>97361</bug_id>
          
          <creation_ts>2012-09-21 14:24:29 -0700</creation_ts>
          <short_desc>range.selectNode throws INVALID_NODE_TYPE_ERR unless node has Document/DocumentFragment ancestor</short_desc>
          <delta_ts>2023-12-29 03:26:32 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</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>0</everconfirmed>
          <reporter name="Nathan Vander Wilt">natevw</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>ap</cc>
    
    <cc>rniwa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>725822</commentid>
    <comment_count>0</comment_count>
    <who name="Nathan Vander Wilt">natevw</who>
    <bug_when>2012-09-21 14:24:29 -0700</bug_when>
    <thetext>The following code fails unexpectedly in WebKit (works in FF, haven&apos;t tested IE):

    var range = document.createRange(),
        root = document.createElement(&apos;div&apos;);
    root.appendChild(document.createElement(&apos;span&apos;));
    range.selectNode(root.firstChild);              // throws INVALID_NODE_TYPE_ERR

It is possible to `range.selectNodeContents(root)` or `range.setStart(root,0), range.setEnd(root,1)` but the `.selectNode` method specifically, errors when it should not. Reference: http://www.w3.org/TR/dom/#dom-range-selectnode — only case INVALID_NODE_TYPE_ERR should be thrown is if root.firstChild.parentNode is null...but that&apos;s unpossible!

Hooking the root element into a document, or even a document fragment via e.g. `document.createDocumentFragment().append(root)`, causes the bug to no longer manifest.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>726904</commentid>
    <comment_count>1</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-09-24 12:12:36 -0700</bug_when>
    <thetext>I think the simplifications that DOM4 makes to selectNode are mostly good. There&apos;s a bunch of things our code does differently though. Someone needs to evaluate what the WebKit code does now and make sure we&apos;re OK with the spec as is (e.g. is it OK for the parent of the refNode to be a DocumentFragment?).

At first glance, the spec looks good to me, but I haven&apos;t taken a thorough look.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2002213</commentid>
    <comment_count>2</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-12-29 03:26:32 -0800</bug_when>
    <thetext>This appears to have been fixed at some point.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>