Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Unified Diff: Source/core/dom/Range.cpp

Issue 178543013: Fix a bug in Range::didSplitTextNode() that may yield an invalid Range object. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix comments in test. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/Range.cpp
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp
index 53a081d175f13e58a51dee60b31a953d1ef101cc..690e034061c641f35c78bfa457fbb2579cfcbda6 100644
--- a/Source/core/dom/Range.cpp
+++ b/Source/core/dom/Range.cpp
@@ -1457,6 +1457,8 @@ void Range::checkDeleteExtract(ExceptionState& exceptionState)
return;
}
+ ASSERT(boundaryPointsValid());
+
if (!commonAncestorContainer(exceptionState) || exceptionState.hadException())
return;
@@ -1765,12 +1767,12 @@ void Range::didMergeTextNodes(NodeWithIndex& oldNode, unsigned offset)
static inline void boundaryTextNodeSplit(RangeBoundaryPoint& boundary, Text* oldNode)
{
- if (boundary.container() != oldNode)
- return;
+ Node* boundaryContainer = boundary.container();
unsigned boundaryOffset = boundary.offset();
- if (boundaryOffset <= oldNode->length())
- return;
- boundary.set(oldNode->nextSibling(), boundaryOffset - oldNode->length(), 0);
+ if (boundary.childBefore() == oldNode)
+ boundary.set(boundaryContainer, boundaryOffset + 1, oldNode->nextSibling());
+ else if (boundary.container() == oldNode && boundaryOffset > oldNode->length())
+ boundary.set(oldNode->nextSibling(), boundaryOffset - oldNode->length(), 0);
}
void Range::didSplitTextNode(Text* oldNode)
@@ -1783,6 +1785,7 @@ void Range::didSplitTextNode(Text* oldNode)
ASSERT(oldNode->nextSibling()->isTextNode());
boundaryTextNodeSplit(m_start, oldNode);
boundaryTextNodeSplit(m_end, oldNode);
+ ASSERT(boundaryPointsValid());
}
void Range::expand(const String& unit, ExceptionState& exceptionState)

Powered by Google App Engine
This is Rietveld 408576698