Title: [280369] trunk/Source/WebCore
Revision
280369
Author
rn...@webkit.org
Date
2021-07-27 19:20:42 -0700 (Tue, 27 Jul 2021)

Log Message

[macOS] Stop away unpaired surrogate pair in findNextWordFromIndex:forward:
https://bugs.webkit.org/show_bug.cgi?id=228496

Reviewed by Darin Adler.

Replace unpaired surrogate pairs with the replacement character before calling findNextWordFromIndex:forward:

* platform/text/mac/TextBoundaries.mm:
(WebCore::findNextWordFromIndex):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (280368 => 280369)


--- trunk/Source/WebCore/ChangeLog	2021-07-28 01:38:05 UTC (rev 280368)
+++ trunk/Source/WebCore/ChangeLog	2021-07-28 02:20:42 UTC (rev 280369)
@@ -1,3 +1,15 @@
+2021-07-27  Ryosuke Niwa  <rn...@webkit.org>
+
+        [macOS] Stop away unpaired surrogate pair in findNextWordFromIndex:forward:
+        https://bugs.webkit.org/show_bug.cgi?id=228496
+
+        Reviewed by Darin Adler.
+
+        Replace unpaired surrogate pairs with the replacement character before calling findNextWordFromIndex:forward:
+
+        * platform/text/mac/TextBoundaries.mm:
+        (WebCore::findNextWordFromIndex):
+
 2021-07-27  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [GPU Process] Code cleanup after r280356

Modified: trunk/Source/WebCore/platform/text/mac/TextBoundaries.mm (280368 => 280369)


--- trunk/Source/WebCore/platform/text/mac/TextBoundaries.mm	2021-07-28 01:38:05 UTC (rev 280368)
+++ trunk/Source/WebCore/platform/text/mac/TextBoundaries.mm	2021-07-28 02:20:42 UTC (rev 280369)
@@ -231,9 +231,13 @@
 int findNextWordFromIndex(StringView text, int position, bool forward)
 {   
 #if USE(APPKIT)
+    String textWithoutUnpairedSurrogates;
+    if (hasUnpairedSurrogate(text)) {
+        textWithoutUnpairedSurrogates = replaceUnpairedSurrogatesWithReplacementCharacter(text.toStringWithoutCopying());
+        text = textWithoutUnpairedSurrogates;
+    }
     auto attributedString = adoptNS([[NSAttributedString alloc] initWithString:text.createNSStringWithoutCopying().get()]);
-    int result = [attributedString nextWordFromIndex:position forward:forward];
-    return result;
+    return [attributedString nextWordFromIndex:position forward:forward];
 #else
     // This very likely won't behave exactly like the non-iPhone version, but it works
     // for the contexts in which it is used on iPhone, and in the future will be
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to