Handle privatecommand messages that pass no data (#112590)

Fixes an error in some text editors.
This commit is contained in:
Justin McCandless 2022-10-19 10:30:23 -07:00 committed by GitHub
parent 8815f60a5a
commit a832a72036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -1877,7 +1877,9 @@ class TextInput {
final Map<String, dynamic> firstArg = args[1] as Map<String, dynamic>;
_currentConnection!._client.performPrivateCommand(
firstArg['action'] as String,
firstArg['data'] as Map<String, dynamic>,
firstArg['data'] == null
? <String, dynamic>{}
: firstArg['data'] as Map<String, dynamic>,
);
break;
case 'TextInputClient.updateFloatingCursor':

View File

@ -562,6 +562,32 @@ void main() {
expect(client.latestMethodCall, 'performPrivateCommand');
});
test('TextInputClient performPrivateCommand method is called with no data at all', () async {
// Assemble a TextInputConnection so we can verify its change in state.
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
const TextInputConfiguration configuration = TextInputConfiguration();
TextInput.attach(client, configuration);
expect(client.latestMethodCall, isEmpty);
// Send performPrivateCommand message.
final ByteData? messageBytes = const JSONMessageCodec().encodeMessage(<String, dynamic>{
'args': <dynamic>[
1,
jsonDecode('{"action": "actionCommand"}'), // No `data` parameter.
],
'method': 'TextInputClient.performPrivateCommand',
});
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
'flutter/textinput',
messageBytes,
(ByteData? _) {},
);
expect(client.latestMethodCall, 'performPrivateCommand');
expect(client.latestPrivateCommandData, <String, dynamic>{});
});
test('TextInputClient showAutocorrectionPromptRect method is called', () async {
// Assemble a TextInputConnection so we can verify its change in state.
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
@ -933,6 +959,7 @@ class FakeTextInputClient with TextInputClient {
String latestMethodCall = '';
final List<String> performedSelectors = <String>[];
late Map<String, dynamic>? latestPrivateCommandData;
@override
TextEditingValue currentTextEditingValue;
@ -946,8 +973,9 @@ class FakeTextInputClient with TextInputClient {
}
@override
void performPrivateCommand(String action, Map<String, dynamic> data) {
void performPrivateCommand(String action, Map<String, dynamic>? data) {
latestMethodCall = 'performPrivateCommand';
latestPrivateCommandData = data;
}
@override