[flutter_tools] handle invalid yaml in plugin dependency (#63526)

This commit is contained in:
Jonah Williams
2020-08-11 19:31:03 -07:00
committed by GitHub
parent 8dcb4c338a
commit 16df32b1eb
2 changed files with 30 additions and 1 deletions

View File

@@ -311,7 +311,14 @@ Plugin _pluginFromPackage(String name, Uri packageRoot) {
if (!globals.fs.isFileSync(pubspecPath)) {
return null;
}
final dynamic pubspec = loadYaml(globals.fs.file(pubspecPath).readAsStringSync());
dynamic pubspec;
try {
pubspec = loadYaml(globals.fs.file(pubspecPath).readAsStringSync());
} on YamlException catch (err) {
globals.printTrace('Failed to parse plugin manifest for $name: $err');
// Do nothing, potentially not a plugin.
}
if (pubspec == null) {
return null;
}

View File

@@ -908,6 +908,28 @@ flutter:
FeatureFlags: () => featureFlags,
});
testUsingContext('Invalid yaml does not crash plugin lookup.', () async {
when(macosProject.existsSync()).thenReturn(true);
when(featureFlags.isMacOSEnabled).thenReturn(true);
when(flutterProject.isModule).thenReturn(true);
// Create a plugin without a pluginClass.
dummyPackageDirectory.parent.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(r'''
"aws ... \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +"%m-%d-%y"), \"Time\": $(date +"%T")}\"
''');
await injectPlugins(flutterProject, checkProjects: true);
final File registrantFile = macosProject.managedDirectory.childFile('GeneratedPluginRegistrant.swift');
expect(registrantFile, exists);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});
testUsingContext('Injecting creates generated Linux registrant', () async {
when(linuxProject.existsSync()).thenReturn(true);
when(featureFlags.isLinuxEnabled).thenReturn(true);