Changeset 148221 in webkit


Ignore:
Timestamp:
Apr 11, 2013 11:56:16 AM (11 years ago)
Author:
rniwa@webkit.org
Message:

Autocorrected text doesn't have a marker of type autocorrected
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:
Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r148220 r148221  
     12013-04-11  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Autocorrected text doesn't have a marker of type autocorrected
     4        https://bugs.webkit.org/show_bug.cgi?id=114337
     5
     6        Reviewed by Darin Adler.
     7
     8        Updated tests to assert the existence of "autocorrected" markers.
     9
     10        * platform/mac/editing/spelling/click-autocorrected-word-expected.png:
     11        * platform/mac/editing/spelling/click-autocorrected-word-expected.txt:
     12        * platform/mac/editing/spelling/click-autocorrected-word.html:
     13        * platform/mac/editing/spelling/delete-into-autocorrected-word-expected.png:
     14        * platform/mac/editing/spelling/delete-into-autocorrected-word-expected.txt:
     15        * platform/mac/editing/spelling/delete-into-autocorrected-word.html:
     16        * platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.png:
     17        * platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.txt:
     18        * platform/mac/editing/spelling/forward-delete-into-autocorrected-word.html:
     19        * platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.png:
     20        * platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.txt:
     21        * platform/mac/editing/spelling/move-cursor-to-autocorrected-word.html:
     22        * platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.png:
     23        * platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.txt:
     24        * platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word.html:
     25
    1262013-04-11  Michelangelo De Simone  <michelangelo@webkit.org>
    227
  • trunk/LayoutTests/platform/mac/editing/spelling/click-autocorrected-word-expected.txt

    r147994 r148221  
    6565PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
    6666PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
    67 PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
     67PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
     68PASS markerRange.toString() is 'message'
     69PASS markerRange.endContainer is textNode
     70PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
     71PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
     72PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
    6873PASS successfullyParsed is true
    6974
  • trunk/LayoutTests/platform/mac/editing/spelling/click-autocorrected-word.html

    r147994 r148221  
    3535        shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
    3636        shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
    37         shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
     37
     38        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
     39        shouldBe("markerRange.toString()", "'message'");
     40        shouldBe("markerRange.endContainer", "textNode");
     41        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
     42        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
     43        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
    3844    }
    3945}
  • trunk/LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word-expected.txt

    r147994 r148221  
    6868PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
    6969PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
    70 PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
     70PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
     71PASS markerRange.toString() is 'message'
     72PASS markerRange.endContainer is textNode
     73PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
     74PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
     75PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
    7176PASS successfullyParsed is true
    7277
  • trunk/LayoutTests/platform/mac/editing/spelling/delete-into-autocorrected-word.html

    r147994 r148221  
    3434        shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
    3535        shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
    36         shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
     36
     37        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
     38        shouldBe("markerRange.toString()", "'message'");
     39        shouldBe("markerRange.endContainer", "textNode");
     40        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
     41        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
     42        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
    3743    }
    3844}
  • trunk/LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word-expected.txt

    r147994 r148221  
    7373PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
    7474PASS internals.markerRangeForNode(textNode, 'spelling', 1) is null
    75 PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
     75PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
     76PASS markerRange.toString() is 'message'
     77PASS markerRange.endContainer is textNode
     78PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
     79PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
     80PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
    7681PASS successfullyParsed is true
    7782
  • trunk/LayoutTests/platform/mac/editing/spelling/forward-delete-into-autocorrected-word.html

    r147994 r148221  
    4343        shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 1)");
    4444
    45         shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
     45        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
     46        shouldBe("markerRange.toString()", "'message'");
     47        shouldBe("markerRange.endContainer", "textNode");
     48        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
     49        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
     50        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
    4651    }
    4752}
  • trunk/LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word-expected.txt

    r147994 r148221  
    6565PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
    6666PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
    67 PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
     67PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
     68PASS markerRange.toString() is 'message'
     69PASS markerRange.endContainer is textNode
     70PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
     71PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
     72PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
    6873PASS successfullyParsed is true
    6974
  • trunk/LayoutTests/platform/mac/editing/spelling/move-cursor-to-autocorrected-word.html

    r147994 r148221  
    3434        shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
    3535        shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
    36         shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
     36
     37        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
     38        shouldBe("markerRange.toString()", "'message'");
     39        shouldBe("markerRange.endContainer", "textNode");
     40        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
     41        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
     42        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
    3743    }
    3844}
  • trunk/LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word-expected.txt

    r147994 r148221  
    6666PASS internals.markerRangeForNode(textNode, 'replacement', 1) is null
    6767PASS internals.markerRangeForNode(textNode, 'spelling', 0) is null
    68 PASS internals.markerRangeForNode(textNode, 'autocorrected', 0) is null
     68PASS markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer is textNode
     69PASS markerRange.toString() is 'message'
     70PASS markerRange.endContainer is textNode
     71PASS markerRange.startOffset is textNode.textContent.indexOf(markerRange.toString())
     72PASS markerRange.endOffset is markerRange.startOffset + markerRange.toString().length
     73PASS internals.markerRangeForNode(textNode, 'autocorrected', 1) is null
    6974PASS successfullyParsed is true
    7075
  • trunk/LayoutTests/platform/mac/editing/spelling/move-cursor-to-beginning-of-autocorrected-word.html

    r147994 r148221  
    3838        shouldBeNull("internals.markerRangeForNode(textNode, 'replacement', 1)");
    3939        shouldBeNull("internals.markerRangeForNode(textNode, 'spelling', 0)");
    40         shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 0)");
     40
     41        shouldBe("markerRange = internals.markerRangeForNode(textNode, 'autocorrected', 0); markerRange.startContainer", "textNode");
     42        shouldBe("markerRange.toString()", "'message'");
     43        shouldBe("markerRange.endContainer", "textNode");
     44        shouldBe("markerRange.startOffset", "textNode.textContent.indexOf(markerRange.toString())");
     45        shouldBe("markerRange.endOffset", "markerRange.startOffset + markerRange.toString().length");
     46        shouldBeNull("internals.markerRangeForNode(textNode, 'autocorrected', 1)");
    4147    }
    4248}
  • trunk/Source/WebCore/ChangeLog

    r148220 r148221  
     12013-04-11  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Autocorrected text doesn't have a marker of type autocorrected
     4        https://bugs.webkit.org/show_bug.cgi?id=114337
     5
     6        Reviewed by Darin Adler.
     7
     8        The bug was caused by markAndReplaceFor's text replacement errornously assuming that there are
     9        no other text checking result starting at the same offset. That resulted in us adjusting location
     10        offsets of the subsequent results pointing at the replaced text, hit an assertion, and blow up.
     11
     12        Fixed the bug by skipping all remaining results for the replaced text since they're no longer
     13        applicable.
     14
     15        Tests: Existing autocorection tests have been updated to assert new behavior.
     16
     17        * editing/Editor.cpp:
     18        (WebCore::Editor::markAndReplaceFor):
     19
    1202013-04-11  Michelangelo De Simone  <michelangelo@webkit.org>
    221
  • trunk/Source/WebCore/editing/Editor.cpp

    r148163 r148221  
    22992299                }
    23002300
     2301                // Skip all other results for the replaced text.
     2302                while (i + 1 < results.size() && results[i + 1].location + offsetDueToReplacement <= resultLocation)
     2303                    i++;
     2304
    23012305                selectionChanged = true;
    23022306                offsetDueToReplacement += replacement.length() - resultLength;
Note: See TracChangeset for help on using the changeset viewer.