Disallow pasting non-text into FlutterTextInputPlugin (flutter/engine#29374)
This commit is contained in:
@@ -900,6 +900,15 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
||||
return _textInputClient != 0;
|
||||
}
|
||||
|
||||
- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender {
|
||||
if (action == @selector(paste:)) {
|
||||
// Forbid pasting images, memojis, or other non-string content.
|
||||
return [UIPasteboard generalPasteboard].string != nil;
|
||||
}
|
||||
|
||||
return [super canPerformAction:action withSender:sender];
|
||||
}
|
||||
|
||||
#pragma mark - UIResponderStandardEditActions Overrides
|
||||
|
||||
- (void)cut:(id)sender {
|
||||
@@ -912,7 +921,10 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
||||
}
|
||||
|
||||
- (void)paste:(id)sender {
|
||||
[self insertText:[UIPasteboard generalPasteboard].string];
|
||||
NSString* pasteboardString = [UIPasteboard generalPasteboard].string;
|
||||
if (pasteboardString != nil) {
|
||||
[self insertText:pasteboardString];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)delete:(id)sender {
|
||||
|
||||
@@ -86,6 +86,9 @@ FLUTTER_ASSERT_ARC
|
||||
textInputPlugin.textInputDelegate = engine;
|
||||
viewController = [FlutterViewController new];
|
||||
textInputPlugin.viewController = viewController;
|
||||
|
||||
// Clear pasteboard between tests.
|
||||
UIPasteboard.generalPasteboard.items = @[];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
@@ -268,6 +271,7 @@ FLUTTER_ASSERT_ARC
|
||||
[inputView selectAll:nil];
|
||||
[inputView cut:nil];
|
||||
[inputView insertText:@"bbbb"];
|
||||
XCTAssertTrue([inputView canPerformAction:@selector(paste:) withSender:nil]);
|
||||
[inputView paste:nil];
|
||||
[inputView selectAll:nil];
|
||||
[inputView copy:nil];
|
||||
@@ -282,6 +286,20 @@ FLUTTER_ASSERT_ARC
|
||||
XCTAssertEqualObjects(substring, @"bbbbaaaabbbbaaaa");
|
||||
}
|
||||
|
||||
- (void)testPastingNonTextDisallowed {
|
||||
NSDictionary* config = self.mutableTemplateCopy;
|
||||
[self setClientId:123 configuration:config];
|
||||
NSArray<FlutterTextInputView*>* inputFields = self.installedInputViews;
|
||||
FlutterTextInputView* inputView = inputFields[0];
|
||||
|
||||
UIPasteboard.generalPasteboard.color = UIColor.redColor;
|
||||
XCTAssertNil(UIPasteboard.generalPasteboard.string);
|
||||
XCTAssertFalse([inputView canPerformAction:@selector(paste:) withSender:nil]);
|
||||
[inputView paste:nil];
|
||||
|
||||
XCTAssertEqualObjects(inputView.text, @"");
|
||||
}
|
||||
|
||||
- (void)testNoZombies {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/62501.
|
||||
FlutterSecureTextInputView* passwordView = [[FlutterSecureTextInputView alloc] init];
|
||||
|
||||
Reference in New Issue
Block a user