Bug 1215816 nsContentIterator::Init(nsIDOMRange*) should not include end node if it's an empty element and the end offset is 0 when mPre is true r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 21 Oct 2015 23:26:20 +0900
changeset 302174 e55d4c56c0ee3bdecef68c73e90ab299a9abbd44
parent 302173 874761c630c2d02abff6bd179985ce81b9ce64a9
child 302175 1e8eb9ccc07d897a65495f992e09c2341f20e987
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs1215816
milestone44.0a1
Bug 1215816 nsContentIterator::Init(nsIDOMRange*) should not include end node if it's an empty element and the end offset is 0 when mPre is true r=smaug
dom/base/nsContentIterator.cpp
--- a/dom/base/nsContentIterator.cpp
+++ b/dom/base/nsContentIterator.cpp
@@ -395,17 +395,28 @@ nsContentIterator::Init(nsIDOMRange* aDO
 
   // Find last node in range.
 
   bool endIsData = endNode->IsNodeOfType(nsINode::eDATA_NODE);
 
   if (endIsData || !endNode->HasChildren() || endIndx == 0) {
     if (mPre) {
       if (endNode->IsContent()) {
-        mLast = endNode->AsContent();
+        // If the end node is an empty element and the end offset is 0,
+        // the last element should be the previous node (i.e., shouldn't
+        // include the end node in the range).
+        if (!endIsData && !endNode->HasChildren() && !endIndx) {
+          mLast = GetPrevSibling(endNode);
+          if (!NodeIsInTraversalRange(mLast, mPre, startNode, startIndx,
+                                      endNode, endIndx)) {
+            mLast = nullptr;
+          }
+        } else {
+          mLast = endNode->AsContent();
+        }
       } else {
         // Not much else to do here...
         mLast = nullptr;
       }
     } else {
       // post-order
       //
       // XXX: In the future, if end offset is before the first character in the