Disallow empty platforms and specific platforms when parsing manifest for plugins (#49262)
This commit is contained in:
@@ -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.'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user