Unverified Commit 672fe20b authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[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
parent 231855fc
......@@ -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 =
......
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