[flutter_tools] handle invalid yaml in plugin dependency (#63526)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user