Skip to content

Commit

Permalink
[Unified Text Replacement] Ephemeral sessions should still return a c…
Browse files Browse the repository at this point in the history
…ontext even if the string lengths differ

https://bugs.webkit.org/show_bug.cgi?id=274278
rdar://125917276

Reviewed by Megan Gardner.

* Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm:
(WebKit::UnifiedTextReplacementController::willBeginTextReplacementSession):

Canonical link: https://commits.webkit.org/278890@main
  • Loading branch information
rr-codes committed May 16, 2024
1 parent f7e6c1a commit 30678c9
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@
auto attributedStringFromRange = WebCore::editingAttributedString(*contextRange);
auto selectedTextCharacterRange = WebCore::characterRange(*contextRange, *selectedTextRange);

auto attributedStringCharacterCount = attributedStringFromRange.string.length();
auto contextRangeCharacterCount = WebCore::characterCount(*contextRange);

// Postcondition: the selected text character range must be a valid range within the
// attributed string formed by the context range; the length of the entire context range
// being equal to the length of the attributed string implies the range is valid.
if (UNLIKELY(attributedStringCharacterCount != contextRangeCharacterCount)) {
RELEASE_LOG_ERROR(UnifiedTextReplacement, "UnifiedTextReplacementController::willBeginTextReplacementSession (%s) => attributed string length (%u) != context range length (%llu)", uuid.toString().utf8().data(), attributedStringCharacterCount, contextRangeCharacterCount);
ASSERT_NOT_REACHED();
completionHandler({ });
return;
if (uuid.isValid()) {
auto attributedStringCharacterCount = attributedStringFromRange.string.length();
auto contextRangeCharacterCount = WebCore::characterCount(*contextRange);

// Postcondition: the selected text character range must be a valid range within the
// attributed string formed by the context range; the length of the entire context range
// being equal to the length of the attributed string implies the range is valid.
if (UNLIKELY(attributedStringCharacterCount != contextRangeCharacterCount)) {
RELEASE_LOG_ERROR(UnifiedTextReplacement, "UnifiedTextReplacementController::willBeginTextReplacementSession (%s) => attributed string length (%u) != context range length (%llu)", uuid.toString().utf8().data(), attributedStringCharacterCount, contextRangeCharacterCount);
ASSERT_NOT_REACHED();
completionHandler({ });
return;
}
}

completionHandler({ { WTF::UUID { 0 }, attributedStringFromRange, selectedTextCharacterRange } });
Expand Down

0 comments on commit 30678c9

Please sign in to comment.