[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:
Christopher Fujino 2023-01-04 12:28:26 -08:00 committed by GitHub
parent 231855fc87
commit 672fe20bde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 8 deletions

View file

@ -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.

View file

@ -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 =