Title: [284141] trunk/Source/WebCore
Revision
284141
Author
[email protected]
Date
2021-10-13 17:57:14 -0700 (Wed, 13 Oct 2021)

Log Message

ASSERT hit in surrogatePairAwareIndex and surrogatePairAwareStart lambdas for text with unpaired surrogates.
https://bugs.webkit.org/show_bug.cgi?id=231606

Patch by Gabriel Nava Marino <[email protected]> on 2021-10-13
Reviewed by Darin Adler and Myles C. Maxfield.

* layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::midWordBreak):
Account for unpaired surrogates in TextUtil::MidWordBreak TextUtil::midWordBreak

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (284140 => 284141)


--- trunk/Source/WebCore/ChangeLog	2021-10-14 00:55:59 UTC (rev 284140)
+++ trunk/Source/WebCore/ChangeLog	2021-10-14 00:57:14 UTC (rev 284141)
@@ -1,3 +1,14 @@
+2021-10-13  Gabriel Nava Marino  <[email protected]>
+
+        ASSERT hit in surrogatePairAwareIndex and surrogatePairAwareStart lambdas for text with unpaired surrogates.
+        https://bugs.webkit.org/show_bug.cgi?id=231606
+
+        Reviewed by Darin Adler and Myles C. Maxfield.
+
+        * layout/formattingContexts/inline/text/TextUtil.cpp:
+        (WebCore::Layout::TextUtil::midWordBreak):
+        Account for unpaired surrogates in TextUtil::MidWordBreak TextUtil::midWordBreak
+
 2021-10-13  Megan Gardner  <[email protected]>
 
         Remove adjustForIOSCaretWhenScrolling() code

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp (284140 => 284141)


--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2021-10-14 00:55:59 UTC (rev 284140)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2021-10-14 00:57:14 UTC (rev 284141)
@@ -149,11 +149,9 @@
     auto text = inlineTextItem.inlineTextBox().content();
     auto surrogatePairAwareIndex = [&] (auto index) {
         // We should never break in the middle of a surrogate pair. They are considered one joint entity.
-        RELEASE_ASSERT(index < text.length());
-        bool isLead = U16_IS_LEAD(text[index]) && (index + 1) < text.length() && U16_IS_TRAIL(text[index + 1]);
-        if (!isLead)
-            return index;
-        return ++index;
+        auto offset = index + 1;
+        U16_SET_CP_LIMIT(text, 0, offset, text.length());
+        return offset - 1;
     };
 
     auto left = startPosition;
@@ -171,15 +169,9 @@
             left = middle + 1;
             leftSideWidth = width;
         } else if (width > availableWidth) {
-            auto surrogatePairAwareStart = [&] (auto index) {
-                bool isTrail = index && U16_IS_LEAD(text[index - 1]) && index < text.length() && U16_IS_TRAIL(text[index]);
-                if (!isTrail)
-                    return index;
-                RELEASE_ASSERT(index);
-                return --index;
-            };
-            // When the substring does not fit, the right side is supposed to be the start of the surrogate pair if applicable. 
-            right = surrogatePairAwareStart(middle);
+            // When the substring does not fit, the right side is supposed to be the start of the surrogate pair if applicable.
+            right = middle;
+            U16_SET_CP_START(text, 0, right);
         } else {
             right = middle + 1;
             leftSideWidth = width;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to