Bug 1723895 - Make `WhiteSpaceVisibilityKeeper::ReplaceText()` call `GetInclusiveNextNBSPPointIfNeedToReplaceWithASCIIWhiteSpace` with end of the replacing range instead of start of it r=m_kato

It tries to replace a following NBSP with an ASCII white-space if there is.
However, it calls the scan method with start of the replacing range.  Therefore,
the assertion in `GetInclusiveNextNBSPPointIfNeedToReplaceWithASCIIWhiteSpace()`
detects this bug.

Note that this occurs only when updating composition string because it's
called with non-collapsed range only for doing it.  Otherwise, selected range
has already been deleted by `HTMLEditor::DeleteSelectionAsSubAction()`.

Unfortunately, I don't have how to make this bug appear.  It seems that the
path does nothing in the wild because it tries to replace a first character
of composition string from an NBSP to a normal white-space, but it'll be
replaced with new composition string anyway.  Therefore, this patch does not
have new tests.

Differential Revision: https://phabricator.services.mozilla.com/D122182
This commit is contained in:
Masayuki Nakano 2021-08-10 23:41:19 +00:00
Родитель baac08facd
Коммит 91fed01266
4 изменённых файлов: 2 добавлений и 5 удалений

Просмотреть файл

@ -12,7 +12,6 @@
<div contenteditable id="editor"><p><br></p></div>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.expectAssertions(2); // Assertions in WSRunScanner::TextFragmentData::GetInclusiveNextNBSPPointIfNeedToReplaceWithASCIIWhiteSpace()
SimpleTest.waitForFocus(function doTests() {
for (let editorId of ["input", "textarea", "editor"]) {
let editor = document.getElementById(editorId);

Просмотреть файл

@ -831,7 +831,7 @@ nsresult WhiteSpaceVisibilityKeeper::ReplaceText(
EditorDOMPointInText atNBSPReplacedWithASCIIWhiteSpace =
textFragmentDataAtEnd
.GetInclusiveNextNBSPPointIfNeedToReplaceWithASCIIWhiteSpace(
pointToInsert);
aRangeToBeReplaced.EndRef());
if (atNBSPReplacedWithASCIIWhiteSpace.IsSet()) {
AutoTransactionsConserveSelection dontChangeMySelection(aHTMLEditor);
nsresult rv = aHTMLEditor.ReplaceTextWithTransaction(

Просмотреть файл

@ -20,7 +20,6 @@
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.expectAssertions(1); // Assertions in WSRunScanner::TextFragmentData::GetInclusiveNextNBSPPointIfNeedToReplaceWithASCIIWhiteSpace()
SimpleTest.waitForFocus(runTests);
const kLF = !navigator.platform.indexOf("Win") ? "\r\n" : "\n";

Просмотреть файл

@ -24,8 +24,7 @@
// '!(GetStateBits() & NS_FRAME_FIRST_REFLOW) || (GetParent()->GetStateBits() &
// NS_FRAME_TOO_DEEP_IN_FRAME_TREE)'" in nsTextFrame.cpp.
// Strangely, this doesn't occur with RDP on Windows.
// 16 assertions are: assertions in WSRunScanner::TextFragmentData::GetInclusiveNextNBSPPointIfNeedToReplaceWithASCIIWhiteSpace()
SimpleTest.expectAssertions(0, 3 + 16);
SimpleTest.expectAssertions(0, 3);
SimpleTest.waitForExplicitFinish();
window.openDialog("window_composition_text_querycontent.xhtml", "_blank",
"chrome,width=600,height=600,noopener", window);