[flutter_tools] dont crash on invalid utf8 in pubspec (#73891)

This commit is contained in:
Jonah Williams 2021-01-13 14:25:16 -08:00 committed by GitHub
parent d4f0c08261
commit 1eb0bb52e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -221,6 +221,12 @@ class FlutterProject {
} on YamlException catch (e) {
logger.printStatus('Error detected in pubspec.yaml:', emphasis: true);
logger.printError('$e');
} on FormatException catch (e) {
logger.printError('Error detected while parsing pubspec.yaml:', emphasis: true);
logger.printError('$e');
} on FileSystemException catch (e) {
logger.printError('Error detected while reading pubspec.yaml:', emphasis: true);
logger.printError('$e');
}
if (manifest == null) {
throwToolExit('Please correct the pubspec.yaml file at $path');

View File

@ -37,6 +37,22 @@ void main() {
);
});
testWithoutContext('invalid utf8 throws a tool exit', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final FlutterProjectFactory projectFactory = FlutterProjectFactory(
fileSystem: fileSystem,
logger: BufferLogger.test(),
);
fileSystem.file('pubspec.yaml').writeAsBytesSync(<int>[0xFFFE]);
/// Technically this should throw a FileSystemException but this is
/// currently a bug in package:file.
expect(
() => projectFactory.fromDirectory(fileSystem.currentDirectory),
throwsToolExit(),
);
});
_testInMemory('fails on invalid pubspec.yaml', () async {
final Directory directory = globals.fs.directory('myproject');
directory.childFile('pubspec.yaml')