Unverified Commit 0833929c authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

Catch UnsupportedError thrown when user provides an asset directory path...

Catch UnsupportedError thrown when user provides an asset directory path containing invalid characters (#141214)

Fixes https://github.com/flutter/flutter/issues/140092
parent e1e470d4
......@@ -912,8 +912,16 @@ class ManifestAssetBundle implements AssetBundle {
Package? attributedPackage,
List<String>? flavors,
}) {
final String directoryPath = _fileSystem.path.join(
assetBase, assetUri.toFilePath(windows: _platform.isWindows));
final String directoryPath;
try {
directoryPath = _fileSystem.path
.join(assetBase, assetUri.toFilePath(windows: _platform.isWindows));
} on UnsupportedError catch (e) {
throwToolExit(
'Unable to search for asset files in directory path "${assetUri.path}". '
'Please ensure that this is valid URI that points to a directory '
'that is available on the local file system.\nError details:\n$e');
}
if (!_fileSystem.directory(directoryPath).existsSync()) {
_logger.printError('Error: unable to find directory entry in pubspec.yaml: $directoryPath');
......
......@@ -153,6 +153,30 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('throws ToolExit when directory entry contains invalid characters', () async {
testFileSystem.file('.packages').createSync();
testFileSystem.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
flutter:
assets:
- https://mywebsite.com/images/
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(() => bundle.build(packagesPath: '.packages'), throwsToolExit(
message: 'Unable to search for asset files in directory path "https%3A//mywebsite.com/images/". '
'Please ensure that this is valid URI that points to a directory that is '
'available on the local file system.\n'
'Error details:\n'
'Unsupported operation: Illegal character in path: https:',
));
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'windows'),
});
testUsingContext('handle removal of wildcard directories', () async {
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
final File pubspec = globals.fs.file('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