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
--- 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