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 303949 e55d4c56c0ee3bdecef68c73e90ab299a9abbd44
parent 303948 874761c630c2d02abff6bd179985ce81b9ce64a9
child 303950 1e8eb9ccc07d897a65495f992e09c2341f20e987
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1215816
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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