From 8a3c98633a35712f4d911f580922bf482e573269 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 22 Jan 2020 10:52:23 -0800 Subject: [PATCH] Disallow empty platforms and specific platforms when parsing manifest for plugins (#49262) --- packages/flutter_tools/lib/src/plugins.dart | 9 +++++++- .../general.shard/plugin_parsing_test.dart | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart index e3ef810301..b5cbe85c99 100644 --- a/packages/flutter_tools/lib/src/plugins.dart +++ b/packages/flutter_tools/lib/src/plugins.dart @@ -202,9 +202,12 @@ class Plugin { static List _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 ['Invalid "platforms" specification.']; + } final List errors = []; if (isInvalid(AndroidPlugin.kConfigKey, AndroidPlugin.validate)) { errors.add('Invalid "android" plugin specification.'); diff --git a/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart b/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart index 540d0295e3..73b225ab7e 100644 --- a/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart +++ b/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart @@ -157,5 +157,27 @@ void main() { expect(plugin.platforms, {}); }); + + test('error on empty platforms', () { + const String pluginYamlRaw = 'platforms:\n'; + + final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap; + expect( + () => Plugin.fromYaml(_kTestPluginName, _kTestPluginPath, pluginYaml, const []), + 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 []), + throwsToolExit(message: 'Invalid "android" plugin specification.'), + ); + }); }); }