This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch base-browser-102.5.0esr-12.0-1 in repository tor-browser.
commit 8b922f50da1629ccc63c5fbeb39fdb728b0fcd19 Author: Ting-Yu Lin tlin@mozilla.com AuthorDate: Fri Sep 2 18:52:36 2022 +0000
Bug 1779846 - Remove an unneeded if-statement in TextServicesDocument::OffsetEntryArray::FindWordRange(). r=masayuki, a=dmeehan
This patch fixed a regression caused by Bug 1730084 Part 4 https://phabricator.services.mozilla.com/D125434, which is intended to preserve the behavior of `WordBreaker::FindWord()`.
Before Bug 1730084 Part 4, `WordBreaker::FindWord()` returns `[aTextLen + 1, aTextLen + 1]` only when `aOffset > aTextLen`. But `WordBreaker::FindWord()` had an assertion `aOffset <= aTextLen` to guarantee the caller never passes `aOffset > aTextLen`. Thus, we can never go into the `if (res.mBegin > strLen)` in `TextServicesDocument::OffsetEntryArray::FindWordRange()`.
However, Bug 1730084 Part 4 wrongly changes the if-statement to `if (range.mEnd == range.mBegin)`, and makes it reachable when `TextServicesDocument::OffsetEntryArray::FindWordRange()` passes `aPos == aLen` into `WordBreaker::FindWord()`. This makes `InitSpellChecker()` failed when `enableSelectionChecking=true`.
This patch deletes the originally unreachable error handling if-statement, and adds an assertion to guarantee `strOffset` and `strLen` is valid.
Differential Revision: https://phabricator.services.mozilla.com/D156210 --- editor/spellchecker/TextServicesDocument.cpp | 5 ++- editor/spellchecker/tests/mochitest.ini | 1 + .../tests/test_spellcheck_selection.html | 36 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/editor/spellchecker/TextServicesDocument.cpp b/editor/spellchecker/TextServicesDocument.cpp index 4bb4be3e24e9..244c72460dfb 100644 --- a/editor/spellchecker/TextServicesDocument.cpp +++ b/editor/spellchecker/TextServicesDocument.cpp @@ -2691,11 +2691,10 @@ TextServicesDocument::OffsetEntryArray::FindWordRange(
const char16_t* str = aAllTextInBlock.BeginReading(); uint32_t strLen = aAllTextInBlock.Length(); + MOZ_ASSERT(strOffset <= strLen, + "The string offset shouldn't be greater than the string length!");
intl::WordRange res = intl::WordBreaker::FindWord(str, strLen, strOffset); - if (res.mBegin == res.mEnd) { - return Err(str ? NS_ERROR_ILLEGAL_VALUE : NS_ERROR_NULL_POINTER); - }
// Strip out the NBSPs at the ends while (res.mBegin <= res.mEnd && IS_NBSP_CHAR(str[res.mBegin])) { diff --git a/editor/spellchecker/tests/mochitest.ini b/editor/spellchecker/tests/mochitest.ini index 950dd5906534..3a82462d36de 100644 --- a/editor/spellchecker/tests/mochitest.ini +++ b/editor/spellchecker/tests/mochitest.ini @@ -49,4 +49,5 @@ skip-if = e10s [test_multiple_content_languages.html] [test_spellcheck_after_edit.html] [test_spellcheck_after_pressing_navigation_key.html] +[test_spellcheck_selection.html] [test_suggest.html] diff --git a/editor/spellchecker/tests/test_spellcheck_selection.html b/editor/spellchecker/tests/test_spellcheck_selection.html new file mode 100644 index 000000000000..0d0887a8f36b --- /dev/null +++ b/editor/spellchecker/tests/test_spellcheck_selection.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Bug 1779846: Test enableSelectionChecking=true on nsIEditorSpellCheck.InitSpellChecker</title> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css" /> + +<div contenteditable lang="en-US">missspelled</div> + +<script> +add_task(async function() { + await new Promise(resolve => SimpleTest.waitForFocus(resolve)); + + let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.import( + "resource://testing-common/AsyncSpellCheckTestHelper.jsm" + ); + + let editingHost = document.querySelector("div[contenteditable][lang=en-US]"); + editingHost.focus(); + + await new Promise(resolve => maybeOnSpellCheck(editingHost, resolve)); + + let editingSession = SpecialPowers.wrap(window).docShell.editingSession; + let editor = editingSession.getEditorForWindow(window); + let spellchecker = SpecialPowers.Cu.createSpellChecker(); + spellchecker.setFilterType(spellchecker.FILTERTYPE_NORMAL); + + /* Select "missspelled" in the <div>. */ + window.getSelection().selectAllChildren(editingHost); + + /* Pass true to InitSpellChecker to spellcheck the current selection of the editor.*/ + await new Promise(resolve => spellchecker.InitSpellChecker(editor, true, resolve)); + + /* InitSpellChecker with enableSelectionChecking=true shouldn't throw any errors. */ + ok(spellchecker.canSpellCheck()); +}); +</script>