This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix a crash when setting clipboardData to null on iOS #32413
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix set clipboardData to null
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,8 @@ @interface FlutterPlatformPluginTest : XCTestCase | |
|
|
||
| @implementation FlutterPlatformPluginTest | ||
|
|
||
| - (void)testHasStrings { | ||
| - (void)testClipboardHasCorrectStrings { | ||
| [UIPasteboard generalPasteboard].string = nil; | ||
| FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; | ||
| std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory = | ||
| std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine); | ||
|
|
@@ -29,7 +30,7 @@ - (void)testHasStrings { | |
| calledSet = true; | ||
| }; | ||
| FlutterMethodCall* methodCallSet = | ||
| [FlutterMethodCall methodCallWithMethodName:@"Clipboard.setClipboardData" | ||
| [FlutterMethodCall methodCallWithMethodName:@"Clipboard.setData" | ||
| arguments:@{@"text" : @"some string"}]; | ||
| [plugin handleMethodCall:methodCallSet result:resultSet]; | ||
| XCTAssertEqual(calledSet, true); | ||
|
|
@@ -39,14 +40,56 @@ - (void)testHasStrings { | |
| __block bool value; | ||
| FlutterResult result = ^(id result) { | ||
| called = true; | ||
| value = result[@"value"]; | ||
| value = [result[@"value"] boolValue]; | ||
| }; | ||
|
||
| FlutterMethodCall* methodCall = | ||
| [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil]; | ||
| [plugin handleMethodCall:methodCall result:result]; | ||
|
|
||
| XCTAssertEqual(called, true); | ||
| XCTAssertEqual(value, true); | ||
|
|
||
| // Call getData and expect it to be "null" | ||
| __block NSString* text; | ||
| FlutterResult getDataResult = ^(id result) { | ||
| text = result[@"text"]; | ||
| }; | ||
| FlutterMethodCall* methodCallGetData = | ||
| [FlutterMethodCall methodCallWithMethodName:@"Clipboard.getData" arguments:@"text/plain"]; | ||
| [plugin handleMethodCall:methodCallGetData result:getDataResult]; | ||
|
|
||
| XCTAssertEqualObjects(text, @"some string"); | ||
| } | ||
|
|
||
| - (void)testClipboardSetDataToNullDoNotCrash { | ||
| [UIPasteboard generalPasteboard].string = nil; | ||
| FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; | ||
| std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory = | ||
| std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine); | ||
| FlutterPlatformPlugin* plugin = | ||
| [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()]; | ||
|
|
||
| // Set some string to the pasteboard. | ||
| __block bool calledSet = false; | ||
| FlutterResult resultSet = ^(id result) { | ||
| calledSet = true; | ||
| }; | ||
| FlutterMethodCall* methodCallSet = | ||
| [FlutterMethodCall methodCallWithMethodName:@"Clipboard.setData" | ||
| arguments:@{@"text" : [NSNull null]}]; | ||
| [plugin handleMethodCall:methodCallSet result:resultSet]; | ||
| XCTAssertEqual(calledSet, true); | ||
|
|
||
| // Call getData and expect it to be "null" | ||
| __block NSString* value; | ||
| FlutterResult result = ^(id result) { | ||
| value = result[@"text"]; | ||
| }; | ||
| FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"Clipboard.getData" | ||
| arguments:@"text/plain"]; | ||
| [plugin handleMethodCall:methodCall result:result]; | ||
|
|
||
| XCTAssertEqualObjects(value, @"null"); | ||
| } | ||
|
|
||
| - (void)testPopSystemNavigator { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.