Skip to content

Commit 672fe20

Browse files
[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
1 parent 231855f commit 672fe20

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

packages/flutter_tools/lib/src/platform_plugins.dart

+6-8
Original file line numberDiff line numberDiff line change
@@ -541,21 +541,19 @@ class WebPlugin extends PluginPlatform {
541541
});
542542

543543
factory WebPlugin.fromYaml(String name, YamlMap yaml) {
544-
assert(validate(yaml));
544+
if (yaml['pluginClass'] is! String) {
545+
throwToolExit('The plugin `$name` is missing the required field `pluginClass` in pubspec.yaml');
546+
}
547+
if (yaml['fileName'] is! String) {
548+
throwToolExit('The plugin `$name` is missing the required field `fileName` in pubspec.yaml');
549+
}
545550
return WebPlugin(
546551
name: name,
547552
pluginClass: yaml['pluginClass'] as String,
548553
fileName: yaml['fileName'] as String,
549554
);
550555
}
551556

552-
static bool validate(YamlMap yaml) {
553-
if (yaml == null) {
554-
return false;
555-
}
556-
return yaml['pluginClass'] is String && yaml['fileName'] is String;
557-
}
558-
559557
static const String kConfigKey = 'web';
560558

561559
/// The name of the plugin.

packages/flutter_tools/test/general.shard/plugin_parsing_test.dart

+23
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ void main() {
290290
]);
291291
});
292292

293+
testWithoutContext('Web plugin tool exits if fileName field missing', () {
294+
final FileSystem fileSystem = MemoryFileSystem.test();
295+
const String pluginYamlRaw =
296+
'platforms:\n'
297+
' web:\n'
298+
' pluginClass: WebSamplePlugin\n';
299+
300+
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
301+
expect(
302+
() => Plugin.fromYaml(
303+
_kTestPluginName,
304+
_kTestPluginPath,
305+
pluginYaml,
306+
null,
307+
const <String>[],
308+
fileSystem: fileSystem,
309+
),
310+
throwsToolExit(
311+
message: 'The plugin `$_kTestPluginName` is missing the required field `fileName` in pubspec.yaml',
312+
),
313+
);
314+
});
315+
293316
testWithoutContext('Windows assumes win32 when no variants are given', () {
294317
final FileSystem fileSystem = MemoryFileSystem.test();
295318
const String pluginYamlRaw =

0 commit comments

Comments
 (0)