Unverified Commit 1eb0bb52 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

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

parent d4f0c082
......@@ -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');
......
......@@ -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')
......
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