mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[flutter_tools] dont crash on invalid utf8 in pubspec (#73891)
This commit is contained in:
parent
d4f0c08261
commit
1eb0bb52e1
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user