Title: [247881] trunk
Revision
247881
Author
[email protected]
Date
2019-07-26 16:38:16 -0700 (Fri, 26 Jul 2019)

Log Message

Moving right by word boundary right before an object element followed by a br element hangs
https://bugs.webkit.org/show_bug.cgi?id=200144

Reviewed by Simon Fraser.

Source/WebCore:

The bug was caused by an infinite loop inside wordBreakIteratorForMinOffsetBoundary when it's trying to
find the previous word boundary at the beginning of a word after the object element and the br element.
In this case, previousBox is at the br element after the object element in the preceding line, and
logicallyPreviousBox ends up returning the same inline box (that of the br element), causing a hang.

Here's how. In logicallyPreviousBox, previousRootInlineBoxCandidatePosition returns a legacy position
immediately after the object element. The root inline box for this position (previousRoot) is the one
that contains the object element and the br element. However, when previousTextOrLineBreakBox is called
on this root inline box, "box" argument of the function is set to nullptr, and as a result, the function
finds and returns the same inline box of the br element that was passed to logicallyPreviousBox.

Fixed the bug by passing the starting inline box to previousRootInlineBoxCandidatePosition when its
root inline box is the previous root inline box (previousRoot). Also applied the same fix to
logicallyNextBox even though we don't have a reproduction for that case for now (RTL test case is
unaffected by nextRootInlineBoxCandidatePosition).

Tests: editing/selection/move-by-word-visually-across-object-element-1.html
       editing/selection/move-by-word-visually-across-object-element-2.html
       editing/selection/move-by-word-visually-across-object-element-3.html

* editing/VisibleUnits.cpp:
(WebCore::logicallyPreviousBox): Fixed the bug.
(WebCore::logicallyNextBox): Ditto.

LayoutTests:

Added regression tests. The second test case involes non-word characters "%)" which are skipped like whitespaces
for the purposes of moving right or left by word granularity. The third test case involves RTL text.

* editing/selection/move-by-word-visually-across-object-element-1-expected.txt: Added.
* editing/selection/move-by-word-visually-across-object-element-1.html: Added.
* editing/selection/move-by-word-visually-across-object-element-2-expected.txt: Added.
* editing/selection/move-by-word-visually-across-object-element-2.html: Added.
* editing/selection/move-by-word-visually-across-object-element-3-expected.txt: Added.
* editing/selection/move-by-word-visually-across-object-element-3.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (247880 => 247881)


--- trunk/LayoutTests/ChangeLog	2019-07-26 22:53:47 UTC (rev 247880)
+++ trunk/LayoutTests/ChangeLog	2019-07-26 23:38:16 UTC (rev 247881)
@@ -1,3 +1,20 @@
+2019-07-26  Ryosuke Niwa  <[email protected]>
+
+        Moving right by word boundary right before an object element followed by a br element hangs
+        https://bugs.webkit.org/show_bug.cgi?id=200144
+
+        Reviewed by Simon Fraser.
+
+        Added regression tests. The second test case involes non-word characters "%)" which are skipped like whitespaces
+        for the purposes of moving right or left by word granularity. The third test case involves RTL text.
+
+        * editing/selection/move-by-word-visually-across-object-element-1-expected.txt: Added.
+        * editing/selection/move-by-word-visually-across-object-element-1.html: Added.
+        * editing/selection/move-by-word-visually-across-object-element-2-expected.txt: Added.
+        * editing/selection/move-by-word-visually-across-object-element-2.html: Added.
+        * editing/selection/move-by-word-visually-across-object-element-3-expected.txt: Added.
+        * editing/selection/move-by-word-visually-across-object-element-3.html: Added.
+
 2019-07-26  Brady Eidson  <[email protected]>
 
         Do not fire readystatechange events at documents about to get replaced by _javascript_ URLs.

Added: trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-1-expected.txt (0 => 247881)


--- trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-1-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-1-expected.txt	2019-07-26 23:38:16 UTC (rev 247881)
@@ -0,0 +1,92 @@
+This tests moving right and left by word boundary across an object element. WebKit should not hang.
+
+Initial state:
+| <div>
+|   "<#selection-caret>Hello"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"
+
+Move right count: 1:
+| <div>
+|   "Hello<#selection-caret>"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"
+
+Move right count: 2:
+| <div>
+|   "Hello"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World<#selection-caret>"
+
+Move right count: 3:
+| <div>
+|   "Hello"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World<#selection-caret>"
+
+Move left count: 1:
+| <div>
+|   "Hello"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "<#selection-caret>World"
+
+Move left count: 2:
+| <div>
+|   "<#selection-caret>Hello"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"
+
+Move left count: 3:
+| <div>
+|   "<#selection-caret>Hello"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"

Added: trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-1.html (0 => 247881)


--- trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-1.html	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-1.html	2019-07-26 23:38:16 UTC (rev 247881)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="editor" contenteditable><div>Hello</div><div><object type="application/x-something" height="50" width="50" border="1"></object><br><div>World</div></div></div>
+<script src=""
+<script>
+
+Markup.description('This tests moving right and left by word boundary across an object element. WebKit should not hang.');
+editor.focus();
+getSelection().setPosition(editor, 0);
+
+Markup.dump(editor, 'Initial state');
+for (let i = 0; i < 3; i++) {
+    getSelection().modify('move', 'right', 'word');
+    Markup.dump(editor, `Move right count: ${i + 1}`);
+}
+
+for (let i = 0; i < 3; i++) {
+    getSelection().modify('move', 'left', 'word');
+    Markup.dump(editor, `Move left count: ${i + 1}`);
+}
+
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-2-expected.txt (0 => 247881)


--- trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-2-expected.txt	2019-07-26 23:38:16 UTC (rev 247881)
@@ -0,0 +1,92 @@
+This tests moving right and left by word boundary across an object element. WebKit should not hang.
+
+Initial state:
+| <div>
+|   "<#selection-caret>Hello %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"
+
+Move right count: 1:
+| <div>
+|   "Hello<#selection-caret> %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"
+
+Move right count: 2:
+| <div>
+|   "Hello %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World<#selection-caret>"
+
+Move right count: 3:
+| <div>
+|   "Hello %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World<#selection-caret>"
+
+Move left count: 1:
+| <div>
+|   "Hello %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "<#selection-caret>World"
+
+Move left count: 2:
+| <div>
+|   "<#selection-caret>Hello %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"
+
+Move left count: 3:
+| <div>
+|   "<#selection-caret>Hello %)"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "World"

Added: trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-2.html (0 => 247881)


--- trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-2.html	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-2.html	2019-07-26 23:38:16 UTC (rev 247881)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="editor" contenteditable><div>Hello %)</div><div><object type="application/x-something" height="50" width="50" border="1"></object><br><div>World</div></div></div>
+<script src=""
+<script>
+
+Markup.description('This tests moving right and left by word boundary across an object element. WebKit should not hang.');
+editor.focus();
+getSelection().setPosition(editor, 0);
+
+Markup.dump(editor, 'Initial state');
+for (let i = 0; i < 3; i++) {
+    getSelection().modify('move', 'right', 'word');
+    Markup.dump(editor, `Move right count: ${i + 1}`);
+}
+
+for (let i = 0; i < 3; i++) {
+    getSelection().modify('move', 'left', 'word');
+    Markup.dump(editor, `Move left count: ${i + 1}`);
+}
+
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-3-expected.txt (0 => 247881)


--- trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-3-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-3-expected.txt	2019-07-26 23:38:16 UTC (rev 247881)
@@ -0,0 +1,92 @@
+This tests moving left and right by word boundary across an object element. WebKit should not hang.
+
+Initial state:
+| <div>
+|   "<#selection-caret>שלום"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "עולם"
+
+Move left count: 1:
+| <div>
+|   "שלום<#selection-caret>"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "עולם"
+
+Move left count: 2:
+| <div>
+|   "שלום"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "עולם<#selection-caret>"
+
+Move left count: 3:
+| <div>
+|   "שלום"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "עולם<#selection-caret>"
+
+Move right count: 1:
+| <div>
+|   "שלום"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "<#selection-caret>עולם"
+
+Move right count: 2:
+| <div>
+|   "<#selection-caret>שלום"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "עולם"
+
+Move right count: 3:
+| <div>
+|   "<#selection-caret>שלום"
+| <div>
+|   <object>
+|     border="1"
+|     height="50"
+|     type="application/x-something"
+|     width="50"
+|   <br>
+|   <div>
+|     "עולם"

Added: trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-3.html (0 => 247881)


--- trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-3.html	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/move-by-word-visually-across-object-element-3.html	2019-07-26 23:38:16 UTC (rev 247881)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html charset="utf-8">
+<body>
+<div id="editor" dir="rtl" contenteditable><div>&#1513;&#1500;&#1493;&#1501;</div><div><object type="application/x-something" height="50" width="50" border="1"></object><br><div>&#1506;&#1493;&#1500;&#1501;</div></div></div>
+<script src=""
+<script>
+
+Markup.description('This tests moving left and right by word boundary across an object element. WebKit should not hang.');
+editor.focus();
+getSelection().setPosition(editor, 0);
+
+Markup.dump(editor, 'Initial state');
+for (let i = 0; i < 3; i++) {
+    getSelection().modify('move', 'left', 'word');
+    Markup.dump(editor, `Move left count: ${i + 1}`);
+}
+
+for (let i = 0; i < 3; i++) {
+    getSelection().modify('move', 'right', 'word');
+    Markup.dump(editor, `Move right count: ${i + 1}`);
+}
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (247880 => 247881)


--- trunk/Source/WebCore/ChangeLog	2019-07-26 22:53:47 UTC (rev 247880)
+++ trunk/Source/WebCore/ChangeLog	2019-07-26 23:38:16 UTC (rev 247881)
@@ -1,3 +1,34 @@
+2019-07-26  Ryosuke Niwa  <[email protected]>
+
+        Moving right by word boundary right before an object element followed by a br element hangs
+        https://bugs.webkit.org/show_bug.cgi?id=200144
+
+        Reviewed by Simon Fraser.
+
+        The bug was caused by an infinite loop inside wordBreakIteratorForMinOffsetBoundary when it's trying to
+        find the previous word boundary at the beginning of a word after the object element and the br element.
+        In this case, previousBox is at the br element after the object element in the preceding line, and
+        logicallyPreviousBox ends up returning the same inline box (that of the br element), causing a hang.
+
+        Here's how. In logicallyPreviousBox, previousRootInlineBoxCandidatePosition returns a legacy position
+        immediately after the object element. The root inline box for this position (previousRoot) is the one
+        that contains the object element and the br element. However, when previousTextOrLineBreakBox is called
+        on this root inline box, "box" argument of the function is set to nullptr, and as a result, the function
+        finds and returns the same inline box of the br element that was passed to logicallyPreviousBox.
+
+        Fixed the bug by passing the starting inline box to previousRootInlineBoxCandidatePosition when its
+        root inline box is the previous root inline box (previousRoot). Also applied the same fix to
+        logicallyNextBox even though we don't have a reproduction for that case for now (RTL test case is
+        unaffected by nextRootInlineBoxCandidatePosition).
+
+        Tests: editing/selection/move-by-word-visually-across-object-element-1.html
+               editing/selection/move-by-word-visually-across-object-element-2.html
+               editing/selection/move-by-word-visually-across-object-element-3.html
+
+        * editing/VisibleUnits.cpp:
+        (WebCore::logicallyPreviousBox): Fixed the bug.
+        (WebCore::logicallyNextBox): Ditto.
+
 2019-07-26  Brady Eidson  <[email protected]>
 
         Do not fire readystatechange events at documents about to get replaced by _javascript_ URLs.

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (247880 => 247881)


--- trunk/Source/WebCore/editing/VisibleUnits.cpp	2019-07-26 22:53:47 UTC (rev 247880)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp	2019-07-26 23:38:16 UTC (rev 247881)
@@ -232,7 +232,7 @@
         if (!previousRoot)
             break;
 
-        previousBox = leafBoxes.previousTextOrLineBreakBox(previousRoot, 0);
+        previousBox = leafBoxes.previousTextOrLineBreakBox(previousRoot, &startBox->root() == previousRoot ? startBox : nullptr);
         if (previousBox) {
             previousBoxInDifferentLine = true;
             return previousBox;
@@ -273,7 +273,7 @@
         if (!nextRoot)
             break;
 
-        nextBox = leafBoxes.nextTextOrLineBreakBox(nextRoot, 0);
+        nextBox = leafBoxes.nextTextOrLineBreakBox(nextRoot, &startBox->root() == nextRoot ? startBox : nullptr);
         if (nextBox) {
             nextBoxInDifferentLine = true;
             return nextBox;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to