Unverified Commit 8a3c9863 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Disallow empty platforms and specific platforms when parsing manifest for plugins (#49262)

parent 320c19e4
......@@ -202,9 +202,12 @@ class Plugin {
static List<String> _validateMultiPlatformYaml(YamlMap yaml) {
bool isInvalid(String key, bool Function(YamlMap) validate) {
if (!yaml.containsKey(key)) {
return false;
}
final dynamic value = yaml[key];
if (value is! YamlMap) {
return false;
return true;
}
final YamlMap yamlValue = value as YamlMap;
if (yamlValue.containsKey('default_package')) {
......@@ -212,6 +215,10 @@ class Plugin {
}
return !validate(yamlValue);
}
if (yaml == null) {
return <String>['Invalid "platforms" specification.'];
}
final List<String> errors = <String>[];
if (isInvalid(AndroidPlugin.kConfigKey, AndroidPlugin.validate)) {
errors.add('Invalid "android" plugin specification.');
......
......@@ -157,5 +157,27 @@ void main() {
expect(plugin.platforms, <String, PluginPlatform> {});
});
test('error on empty platforms', () {
const String pluginYamlRaw = 'platforms:\n';
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
expect(
() => Plugin.fromYaml(_kTestPluginName, _kTestPluginPath, pluginYaml, const <String>[]),
throwsToolExit(message: 'Invalid "platforms" specification.'),
);
});
test('error on empty platform', () {
const String pluginYamlRaw =
'platforms:\n'
' android:\n';
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
expect(
() => Plugin.fromYaml(_kTestPluginName, _kTestPluginPath, pluginYaml, const <String>[]),
throwsToolExit(message: 'Invalid "android" plugin specification.'),
);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment