[flutter_tools] fix crash if the platform section was a list (#60927)

Missed validation to go with cast. Added test case to reproduce.
This commit is contained in:
Jonah Williams
2020-07-07 10:24:42 -07:00
committed by GitHub
parent db5a62b0ee
commit 846418b60b
2 changed files with 24 additions and 0 deletions

View File

@@ -214,6 +214,10 @@ class Plugin {
}
if (usesNewPluginFormat) {
if (yaml['platforms'] != null && yaml['platforms'] is! YamlMap) {
const String errorMessage = 'flutter.plugin.platforms should be a map with the platform name as the key';
return <String>[errorMessage];
}
return _validateMultiPlatformYaml(yaml['platforms'] as YamlMap);
} else {
return _validateLegacyYaml(yaml);

View File

@@ -943,6 +943,26 @@ flutter:
<String, dynamic>{'pluginClass': 'SomeClass',
'package': 'com.example'});
});
testWithoutContext('FlutterManifest validates a platform section that is a list '
'instead of a map', () {
const String manifest = '''
name: test
flutter:
plugin:
platforms:
- android
''';
final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, null);
expect(logger.errorText,
contains('flutter.plugin.platforms should be a map with the platform name as the key'));
});
}
Matcher matchesManifest({