Title: [249508] trunk
Revision
249508
Author
[email protected]
Date
2019-09-04 18:17:13 -0700 (Wed, 04 Sep 2019)

Log Message

-[WKContentView selectedText] returns an empty string when selecting more than 200 characters
https://bugs.webkit.org/show_bug.cgi?id=201471
<rdar://problem/55039227>

Reviewed by Tim Horton.

Source/WebKit:

The fix for <rdar://problem/54308019> is contingent on -[WKContentView selectedText] returning a non-empty
result in the case where text is selected. However, in WebKit, if more than 200 characters are selected,
-selectedText ends up returning nothing.

This is due to logic added in trac.webkit.org/r167624 that was intended to return the selected text in
PostLayoutData's wordAtSelection, up to a maximum of 200 characters, likely for performance and/or security
reasons. However, instead of truncating at 200 characters, the change simply drops wordAtSelection altogether.
This patch fixes this issue by taking the first 200 characters of the selected text.

Test: EditorStateTests.SelectedText

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState const):

Tools:

Add an API test to ensure that -selectedText is non-empty in the case where more than 200 characters are
selected.

* TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (249507 => 249508)


--- trunk/Source/WebKit/ChangeLog	2019-09-05 01:02:17 UTC (rev 249507)
+++ trunk/Source/WebKit/ChangeLog	2019-09-05 01:17:13 UTC (rev 249508)
@@ -1,3 +1,25 @@
+2019-09-04  Wenson Hsieh  <[email protected]>
+
+        -[WKContentView selectedText] returns an empty string when selecting more than 200 characters
+        https://bugs.webkit.org/show_bug.cgi?id=201471
+        <rdar://problem/55039227>
+
+        Reviewed by Tim Horton.
+
+        The fix for <rdar://problem/54308019> is contingent on -[WKContentView selectedText] returning a non-empty
+        result in the case where text is selected. However, in WebKit, if more than 200 characters are selected,
+        -selectedText ends up returning nothing.
+
+        This is due to logic added in trac.webkit.org/r167624 that was intended to return the selected text in
+        PostLayoutData's wordAtSelection, up to a maximum of 200 characters, likely for performance and/or security
+        reasons. However, instead of truncating at 200 characters, the change simply drops wordAtSelection altogether.
+        This patch fixes this issue by taking the first 200 characters of the selected text.
+
+        Test: EditorStateTests.SelectedText
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::platformEditorState const):
+
 2019-09-04  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Local Overrides - Provide substitution content for resource loads (URL based)

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (249507 => 249508)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-09-05 01:02:17 UTC (rev 249507)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-09-05 01:17:13 UTC (rev 249508)
@@ -261,8 +261,7 @@
             selectedText = plainTextReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true);
             postLayoutData.selectedTextLength = selectedText.length();
             const int maxSelectedTextLength = 200;
-            if (selectedText.length() <= maxSelectedTextLength)
-                postLayoutData.wordAtSelection = selectedText;
+            postLayoutData.wordAtSelection = selectedText.left(maxSelectedTextLength);
         }
         // FIXME: We should disallow replace when the string contains only CJ characters.
         postLayoutData.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.isAllSpecialCharacters<isHTMLSpace>();

Modified: trunk/Tools/ChangeLog (249507 => 249508)


--- trunk/Tools/ChangeLog	2019-09-05 01:02:17 UTC (rev 249507)
+++ trunk/Tools/ChangeLog	2019-09-05 01:17:13 UTC (rev 249508)
@@ -1,3 +1,18 @@
+2019-09-04  Wenson Hsieh  <[email protected]>
+
+        -[WKContentView selectedText] returns an empty string when selecting more than 200 characters
+        https://bugs.webkit.org/show_bug.cgi?id=201471
+        <rdar://problem/55039227>
+
+        Reviewed by Tim Horton.
+
+        Add an API test to ensure that -selectedText is non-empty in the case where more than 200 characters are
+        selected.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2019-09-04  Jonathan Bedard  <[email protected]>
 
         results.webkit.org: Fix mobile vs desktop mode

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm (249507 => 249508)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm	2019-09-05 01:02:17 UTC (rev 249507)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm	2019-09-05 01:17:13 UTC (rev 249508)
@@ -420,6 +420,15 @@
     EXPECT_FALSE([textInput isPosition:textInput.selectedTextRange.end atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionForward]);
 }
 
+TEST(EditorStateTests, SelectedText)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadTestPageNamed:@"lots-of-text"];
+    [webView _synchronouslyExecuteEditCommand:@"SelectAll" argument:nil];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_GT([[webView textInputContentView] selectedText].length, 0U);
+}
+
 #endif // PLATFORM(IOS_FAMILY)
 
 } // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (249507 => 249508)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-09-05 01:02:17 UTC (rev 249507)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-09-05 01:17:13 UTC (rev 249508)
@@ -163,6 +163,7 @@
 @protocol UIWKInteractionViewProtocol
 - (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
 - (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler;
+@property (nonatomic, readonly) NSString *selectedText;
 @end
 
 IGNORE_WARNINGS_BEGIN("deprecated-implementations")
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to