Skip to content
Next Next commit
fix
  • Loading branch information
andrewkolos committed Jan 26, 2024
commit 233646478937cd359ef0364cb3caa1453f9bfcb9
13 changes: 11 additions & 2 deletions packages/flutter_tools/lib/src/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:standard_message_codec/standard_message_codec.dart';
import 'base/common.dart';
import 'base/context.dart';
import 'base/deferred_component.dart';
import 'base/error_handling_io.dart';
import 'base/file_system.dart';
import 'base/logger.dart';
import 'base/platform.dart';
Expand Down Expand Up @@ -1298,8 +1299,16 @@ class _AssetDirectoryCache {
List<String> variantsFor(String assetPath) {
final String directory = _fileSystem.path.dirname(assetPath);

if (!_fileSystem.directory(directory).existsSync()) {
return const <String>[];
try {
if (!_fileSystem.directory(directory).existsSync()) {
return const <String>[];
}
} on FileSystemException catch (e) {
throwToolExit(
'Unable to check the existence of asset file "$assetPath". '
'Ensure that the asset file is declared is a valid local file system path.\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-'Ensure that the asset file is declared is a valid local file system path.\n'
+'Ensure that the asset file is declared and is a valid local file system path.\n'

'Details: $e',
);
}

if (_cache.containsKey(assetPath)) {
Expand Down
31 changes: 30 additions & 1 deletion packages/flutter_tools/test/general.shard/asset_bundle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('throws ToolExit when directory entry contains invalid characters', () async {
testUsingContext('throws ToolExit when directory entry contains invalid characters (Windows only)', () async {
testFileSystem.file('.packages').createSync();
testFileSystem.file('pubspec.yaml')
..createSync()
Expand All @@ -177,6 +177,35 @@ flutter:
Platform: () => FakePlatform(operatingSystem: 'windows'),
});

testUsingContext('throws ToolExit when file entry contains invalid characters (Windows only)', () async {
globals.fs.file('.packages').createSync();
globals.fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
flutter:
assets:
- http://website.com/hi.png
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(() => bundle.build(packagesPath: '.packages'), throwsToolExit(
message: 'Unable to check the existence of asset file ',
));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows,
opHandle: (String context, FileSystemOp operation) {
if (operation == FileSystemOp.exists && context == r'C:\http:\\website.com') {
throw const FileSystemException(
r"FileSystemException: Exists failed, path = 'C:\http:\\website.com' "
'(OS Error: The filename, directory name, or volume label syntax is '
'incorrect., errno = 123)',
);
}
},),
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')
Expand Down