Catch UnsupportedError thrown when user provides an asset directory path containing invalid characters (#141214)
Fixes https://github.com/flutter/flutter/issues/140092
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user