mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
[flutter_tools] Fix null check in parsing web plugin from pubspec.yaml (#117939)
* fix null check in parsing web plugin yaml * revert accidental diff * remove comment
This commit is contained in:
parent
231855fc87
commit
672fe20bde
|
@ -541,7 +541,12 @@ class WebPlugin extends PluginPlatform {
|
|||
});
|
||||
|
||||
factory WebPlugin.fromYaml(String name, YamlMap yaml) {
|
||||
assert(validate(yaml));
|
||||
if (yaml['pluginClass'] is! String) {
|
||||
throwToolExit('The plugin `$name` is missing the required field `pluginClass` in pubspec.yaml');
|
||||
}
|
||||
if (yaml['fileName'] is! String) {
|
||||
throwToolExit('The plugin `$name` is missing the required field `fileName` in pubspec.yaml');
|
||||
}
|
||||
return WebPlugin(
|
||||
name: name,
|
||||
pluginClass: yaml['pluginClass'] as String,
|
||||
|
@ -549,13 +554,6 @@ class WebPlugin extends PluginPlatform {
|
|||
);
|
||||
}
|
||||
|
||||
static bool validate(YamlMap yaml) {
|
||||
if (yaml == null) {
|
||||
return false;
|
||||
}
|
||||
return yaml['pluginClass'] is String && yaml['fileName'] is String;
|
||||
}
|
||||
|
||||
static const String kConfigKey = 'web';
|
||||
|
||||
/// The name of the plugin.
|
||||
|
|
|
@ -290,6 +290,29 @@ void main() {
|
|||
]);
|
||||
});
|
||||
|
||||
testWithoutContext('Web plugin tool exits if fileName field missing', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
const String pluginYamlRaw =
|
||||
'platforms:\n'
|
||||
' web:\n'
|
||||
' pluginClass: WebSamplePlugin\n';
|
||||
|
||||
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
|
||||
expect(
|
||||
() => Plugin.fromYaml(
|
||||
_kTestPluginName,
|
||||
_kTestPluginPath,
|
||||
pluginYaml,
|
||||
null,
|
||||
const <String>[],
|
||||
fileSystem: fileSystem,
|
||||
),
|
||||
throwsToolExit(
|
||||
message: 'The plugin `$_kTestPluginName` is missing the required field `fileName` in pubspec.yaml',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Windows assumes win32 when no variants are given', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
const String pluginYamlRaw =
|
||||
|
|
Loading…
Reference in a new issue