Autocorrected text doesn't have a marker of type autocorrected
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2013 18:56:16 +0000 (18:56 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2013 18:56:16 +0000 (18:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=114337

Reviewed by Darin Adler.

Source/WebCore:

The bug was caused by markAndReplaceFor's text replacement errornously assuming that there are
no other text checking result starting at the same offset. That resulted in us adjusting location
offsets of the subsequent results pointing at the replaced text, hit an assertion, and blow up.

Fixed the bug by skipping all remaining results for the replaced text since they're no longer
applicable.

Tests: Existing autocorection tests have been updated to assert new behavior.

* editing/Editor.cpp:
(WebCore::Editor::markAndReplaceFor):

LayoutTests:

Updated tests to assert the existence of "autocorrected" markers.

* platform/mac/editing/spelling/click-autocorrected-word-expected.png:
* platform/mac/editing/spelling/click-autocorrected-word-expected.txt:
* platform/mac/editing/spelling/click-autocorrected-word.html:
* platform/mac/editing/spelling/delete-into-autocorrected-word-expected.png:
* platform/mac/editing/spelling/delete-into-autocorrected-word-expected.txt:
* platform/mac/editing/spelling/delete-into-autocorrected-word.html:
* platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.png:
* platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.txt:
* platform/mac/editing/spelling/forward-delete-into-autocorrected-word.html:
* platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.png:
* platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.txt:
* platform/mac/editing/spelling/move-cursor-to-autocorrected-word.html:
* platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.png:
* platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.txt:
* platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@148221 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/editing/spelling/click-autocorrected-word-expected.png
LayoutTests/platform/mac/editing/spelling/click-autocorrected-word-expected.txt
LayoutTests/platform/mac/editing/spelling/click-autocorrected-word.html
LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word-expected.png
LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word-expected.txt
LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word.html
LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.png
LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.txt
LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word.html
LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.png
LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.txt
LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word.html
LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.png
LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.txt
LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word.html
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp

index e66911d314c71b242ecaa9a0723b28b18848689a..c35b18e3c8676973702b4b4aac9ce71569ac66a8 100644 (file)
@@ -1,3 +1,28 @@
+2013-04-11  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Autocorrected text doesn't have a marker of type autocorrected
+        https://bugs.webkit.org/show_bug.cgi?id=114337
+
+        Reviewed by Darin Adler.
+
+        Updated tests to assert the existence of "autocorrected" markers.
+
+        * platform/mac/editing/spelling/click-autocorrected-word-expected.png:
+        * platform/mac/editing/spelling/click-autocorrected-word-expected.txt:
+        * platform/mac/editing/spelling/click-autocorrected-word.html:
+        * platform/mac/editing/spelling/delete-into-autocorrected-word-expected.png:
+        * platform/mac/editing/spelling/delete-into-autocorrected-word-expected.txt:
+        * platform/mac/editing/spelling/delete-into-autocorrected-word.html:
+        * platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.png:
+        * platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.txt:
+        * platform/mac/editing/spelling/forward-delete-into-autocorrected-word.html:
+        * platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.png:
+        * platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.txt:
+        * platform/mac/editing/spelling/move-cursor-to-autocorrected-word.html:
+        * platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.png:
+        * platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.txt:
+        * platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word.html:
+
 2013-04-11  Michelangelo De Simone  <michelangelo@webkit.org>
 
         [CSS Shaders] Parse the geometry descriptor
index dbf35ffd88d10b6ccf6b2e334b312e6477d66a84..a75e941a85e4b54c37d351548bc4865f65413412 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/spelling/click-autocorrected-word-expected.png and b/LayoutTests/platform/mac/editing/spelling/click-autocorrected-word-expected.png differ
index 40f7ab5aeea0b0c5461862792de1cb1b26d96eec..407df1702c797137680a64a1f89bb3243a86dbc0 100644 (file)
@@ -64,7 +64,12 @@ PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toStrin
 PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
 PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
 PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
-PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
+PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
+PASS markerRange.toString() is 'message'
+PASS markerRange.endContainer is textNode
+PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
+PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
+PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 69a74f9962510683ff85e17e8903adeecc52549a..11177bb2e3adee0adebc28340c8eb303e30e66e0 100644 (file)
@@ -34,7 +34,13 @@ function editingTest() {
         shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
         shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
         shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
-        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
+
+        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
+        shouldBe("markerRange.toString()", "'message'");
+        shouldBe("markerRange.endContainer", "textNode");
+        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
+        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
+        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
     }
 }
 
index adc66b0a8787a1adc7731d1127318d8bbaea70a1..91e3f5de205007b8ad4c7ba058c34ea988d5aa25 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word-expected.png and b/LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word-expected.png differ
index c889cb63bd083dff2a17cd3f6cb922e4e332ebd6..c8a47ec6c026860be4d54fbae4a7e34b16dee695 100644 (file)
@@ -67,7 +67,12 @@ PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toStrin
 PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
 PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
 PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
-PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
+PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
+PASS markerRange.toString() is 'message'
+PASS markerRange.endContainer is textNode
+PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
+PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
+PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 026e71a89a93674a16f62a333854c43575eeb720..6f833f8e05db89546cb7cb8ee32f3cf082c0e08b 100644 (file)
@@ -33,7 +33,13 @@ function editingTest() {
         shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
         shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
         shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
-        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
+
+        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
+        shouldBe("markerRange.toString()", "'message'");
+        shouldBe("markerRange.endContainer", "textNode");
+        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
+        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
+        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
     }
 }
 
index 5dbf3122b839ee077059869dd32830321b3a34cd..1b3be0487852b4c8e9a550c570cf65df93136523 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.png and b/LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.png differ
index 85a2f4b6cf90377e54726ee0e5369e709b81da7e..fc345d5a076854de501e72d25aaedb9bcc250230 100644 (file)
@@ -72,7 +72,12 @@ PASS markerRange.endContainer is textNode
 PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
 PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
 PASS internals.markerRangeForNode(textNode, 'spelling', 1) is null
-PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
+PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
+PASS markerRange.toString() is 'message'
+PASS markerRange.endContainer is textNode
+PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
+PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
+PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 95e1c7c0eecd9ea0f516996462a6291cf13e379b..17ca5bfec53b27d08cfa04b40d0832bb8c277e30 100644 (file)
@@ -42,7 +42,12 @@ function editingTest() {
         shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
         shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 1)");
 
-        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
+        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
+        shouldBe("markerRange.toString()", "'message'");
+        shouldBe("markerRange.endContainer", "textNode");
+        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
+        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
+        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
     }
 }
 
index e5b856ff12790214632b31782db7f0713f398c4d..15945aaa192a868b0592ac85258f9d83d71734cc 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.png and b/LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.png differ
index 34725807ff643b26048b6a980582b0da8ca4f037..f0fa1f4e6250c25487c8160bcbea80f1aa331b02 100644 (file)
@@ -64,7 +64,12 @@ PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toStrin
 PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
 PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
 PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
-PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
+PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
+PASS markerRange.toString() is 'message'
+PASS markerRange.endContainer is textNode
+PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
+PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
+PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 7f61a133295572b129434818acaabba6d1250fad..63502abd332aee4a010e8b27a759410ef138c535 100644 (file)
@@ -33,7 +33,13 @@ function editingTest() {
         shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
         shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
         shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
-        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
+
+        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
+        shouldBe("markerRange.toString()", "'message'");
+        shouldBe("markerRange.endContainer", "textNode");
+        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
+        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
+        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
     }
 }
 
index 979abc4d7e9d6c75da6b6c3d1f1abe04b02981f6..22b39bc454d9ee100db9dd18da4cc97a6ed5ce18 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.png and b/LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.png differ
index 96d4555440702a044cbc9f836c2a635305cbbd37..fa027716f878a0e9041b181223265ba142afbaf8 100644 (file)
@@ -65,7 +65,12 @@ PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toStrin
 PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
 PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
 PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
-PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
+PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
+PASS markerRange.toString() is 'message'
+PASS markerRange.endContainer is textNode
+PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
+PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
+PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 51887dcf8426eba7410a8b1d741091ea4a5bc384..c9cb2ace4d901b0e1a5bf862a864cee63174d47f 100644 (file)
@@ -37,7 +37,13 @@ function editingTest() {
         shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
         shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
         shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
-        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
+
+        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
+        shouldBe("markerRange.toString()", "'message'");
+        shouldBe("markerRange.endContainer", "textNode");
+        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
+        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
+        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
     }
 }
 
index 2aa65e38e13bc0c1352b79ae3fe4ea62533cead8..6d25f12fa98017f37b25a2882a2a425d8a869624 100644 (file)
@@ -1,3 +1,22 @@
+2013-04-11  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Autocorrected text doesn't have a marker of type autocorrected
+        https://bugs.webkit.org/show_bug.cgi?id=114337
+
+        Reviewed by Darin Adler.
+
+        The bug was caused by markAndReplaceFor's text replacement errornously assuming that there are
+        no other text checking result starting at the same offset. That resulted in us adjusting location
+        offsets of the subsequent results pointing at the replaced text, hit an assertion, and blow up.
+
+        Fixed the bug by skipping all remaining results for the replaced text since they're no longer
+        applicable.
+
+        Tests: Existing autocorection tests have been updated to assert new behavior.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::markAndReplaceFor):
+
 2013-04-11  Michelangelo De Simone  <michelangelo@webkit.org>
 
         [CSS Shaders] Parse the geometry descriptor
index 1874a51fe6ae6f24ad9491f442d24bf56e85955b..d3130c7199011e598e9761cbdc797c1f3eb68c7e 100644 (file)
@@ -2298,6 +2298,10 @@ void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vect
                         cache->postNotification(root, AXObjectCache::AXAutocorrectionOccured, true);
                 }
 
+                // Skip all other results for the replaced text.
+                while (i + 1 < results.size() && results[i + 1].location + offsetDueToReplacement <= resultLocation)
+                    i++;
+
                 selectionChanged = true;
                 offsetDueToReplacement += replacement.length() - resultLength;
                 if (resultLocation < selectionOffset)