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

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 conflicts. 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/RangeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Range.cpp
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp
index 28b4b67bd18457d64bd17efde0213b555d88779a..256a1507f887f49489623f74f776808a3fae96d7 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;
@@ -1764,12 +1766,12 @@ void Range::didMergeTextNodes(const 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)
@@ -1781,6 +1783,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)
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/RangeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698