Commit fa791406 authored by yoichio@chromium.org's avatar yoichio@chromium.org

[Editing] Make loop condition in insertOrderedList::doApply strict.

The while loop starting from L163 in insertOrderedList::doApply uses two loop 
variables, |startOfCurrentParagrap| and |startOfLastParagraph|.
They are of Position type and modified in loop.
Old implementation can go into infinite loop if |startOfCurrentParagrap| skips over 
|startOfLastParagraph|.
Thus this CL adds condition that |startOfCurrentParagrap| 
 should be before |startOfLastParagraph|.

TEST=LayoutTests/editing/execCommand/execCommand/insert-list-infinite-loop2.html

Review URL: https://codereview.chromium.org/1285103002

git-svn-id: svn://svn.chromium.org/blink/trunk@200956 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f6ff1588
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<div id="log"></div>
<table contenteditable="true"><tbody><tr><td>
<table><tbody><tr><td>
<ol id="ol"><li>AAA<br><br></li><li><br></li><li>BBB<br>CCC</li></ol>
</td></tr></tbody></table>
DDD<div style="-webkit-user-select: none;"></div><div style="display: inline-block; border:solid;"></div>
</td></tr></tbody></table>
<script>
test(function () {
getSelection().selectAllChildren(ol);
document.execCommand('insertOrderedList');
});
</script>
</body>
......@@ -106,6 +106,13 @@ InsertListCommand::InsertListCommand(Document& document, Type type)
{
}
static bool inSameTreeAndOrdered(const VisiblePosition& shouldBeFormer, const VisiblePosition& shouldBeLater)
{
const Position formerPosition = shouldBeFormer.deepEquivalent();
const Position laterPosition = shouldBeLater.deepEquivalent();
return Position::commonAncestorTreeScope(formerPosition, laterPosition) && comparePositions(formerPosition, laterPosition) <= 0;
}
void InsertListCommand::doApply()
{
if (!endingSelection().isNonOrphanedCaretOrRange())
......@@ -153,7 +160,7 @@ void InsertListCommand::doApply()
forceListCreation = !selectionHasListOfType(selection, listTag);
VisiblePosition startOfCurrentParagraph = startOfSelection;
while (startOfCurrentParagraph.isNotNull() && !inSameParagraph(startOfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) {
while (inSameTreeAndOrdered(startOfCurrentParagraph, startOfLastParagraph) && !inSameParagraph(startOfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) {
// doApply() may operate on and remove the last paragraph of the selection from the document
// if it's in the same list item as startOfCurrentParagraph. Return early to avoid an
// infinite loop and because there is no more work to be done.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment