Changeset 249508 in webkit


Ignore:
Timestamp:
Sep 4, 2019 6:17:13 PM (5 years ago)
Author:
Wenson Hsieh
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:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r249504 r249508  
     12019-09-04  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        -[WKContentView selectedText] returns an empty string when selecting more than 200 characters
     4        https://bugs.webkit.org/show_bug.cgi?id=201471
     5        <rdar://problem/55039227>
     6
     7        Reviewed by Tim Horton.
     8
     9        The fix for <rdar://problem/54308019> is contingent on -[WKContentView selectedText] returning a non-empty
     10        result in the case where text is selected. However, in WebKit, if more than 200 characters are selected,
     11        -selectedText ends up returning nothing.
     12
     13        This is due to logic added in trac.webkit.org/r167624 that was intended to return the selected text in
     14        PostLayoutData's wordAtSelection, up to a maximum of 200 characters, likely for performance and/or security
     15        reasons. However, instead of truncating at 200 characters, the change simply drops wordAtSelection altogether.
     16        This patch fixes this issue by taking the first 200 characters of the selected text.
     17
     18        Test: EditorStateTests.SelectedText
     19
     20        * WebProcess/WebPage/ios/WebPageIOS.mm:
     21        (WebKit::WebPage::platformEditorState const):
     22
    1232019-09-04  Joseph Pecoraro  <pecoraro@apple.com>
    224
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r249435 r249508  
    262262            postLayoutData.selectedTextLength = selectedText.length();
    263263            const int maxSelectedTextLength = 200;
    264             if (selectedText.length() <= maxSelectedTextLength)
    265                 postLayoutData.wordAtSelection = selectedText;
     264            postLayoutData.wordAtSelection = selectedText.left(maxSelectedTextLength);
    266265        }
    267266        // FIXME: We should disallow replace when the string contains only CJ characters.
  • trunk/Tools/ChangeLog

    r249506 r249508  
     12019-09-04  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        -[WKContentView selectedText] returns an empty string when selecting more than 200 characters
     4        https://bugs.webkit.org/show_bug.cgi?id=201471
     5        <rdar://problem/55039227>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add an API test to ensure that -selectedText is non-empty in the case where more than 200 characters are
     10        selected.
     11
     12        * TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
     13        (TestWebKitAPI::TEST):
     14        * TestWebKitAPI/ios/UIKitSPI.h:
     15
    1162019-09-04  Jonathan Bedard  <jbedard@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm

    r247679 r249508  
    421421}
    422422
     423TEST(EditorStateTests, SelectedText)
     424{
     425    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     426    [webView synchronouslyLoadTestPageNamed:@"lots-of-text"];
     427    [webView _synchronouslyExecuteEditCommand:@"SelectAll" argument:nil];
     428    [webView waitForNextPresentationUpdate];
     429    EXPECT_GT([[webView textInputContentView] selectedText].length, 0U);
     430}
     431
    423432#endif // PLATFORM(IOS_FAMILY)
    424433
  • trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h

    r248487 r249508  
    164164- (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
    165165- (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler;
     166@property (nonatomic, readonly) NSString *selectedText;
    166167@end
    167168
Note: See TracChangeset for help on using the changeset viewer.