mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Handle empty entry in asset list and add more explicit validation (#41735)
This commit is contained in:
parent
b1a6aa3ab8
commit
0af2a84cbb
@ -186,16 +186,27 @@ class FlutterManifest {
|
||||
: fontList.map<Map<String, dynamic>>(castStringKeyedMap).toList();
|
||||
}
|
||||
|
||||
List<Uri> get assets {
|
||||
List<Uri> get assets => _assets ??= _computeAssets();
|
||||
List<Uri> _assets;
|
||||
List<Uri> _computeAssets() {
|
||||
final List<dynamic> assets = _flutterDescriptor['assets'];
|
||||
if (assets == null) {
|
||||
return const <Uri>[];
|
||||
}
|
||||
return assets
|
||||
.cast<String>()
|
||||
.map<String>(Uri.encodeFull)
|
||||
?.map<Uri>(Uri.parse)
|
||||
?.toList();
|
||||
final List<Uri> results = <Uri>[];
|
||||
for (Object asset in assets) {
|
||||
if (asset is! String || asset == null || asset == '') {
|
||||
printError('Asset manifest contains a null or empty uri.');
|
||||
continue;
|
||||
}
|
||||
final String stringAsset = asset;
|
||||
try {
|
||||
results.add(Uri.parse(Uri.encodeFull(stringAsset)));
|
||||
} on FormatException {
|
||||
printError('Asset manifest contains invalid uri: $asset.');
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
List<Font> _fonts;
|
||||
|
||||
@ -572,6 +572,26 @@ flutter:
|
||||
expect(flutterManifest, null);
|
||||
expect(logger.errorText, contains('Expected a map.'));
|
||||
});
|
||||
|
||||
testUsingContext('Does not crash on empty entry', () async {
|
||||
final BufferLogger logger = context.get<Logger>();
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
assets:
|
||||
- lib/gallery/example_code.dart
|
||||
-
|
||||
''';
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
|
||||
final List<Uri> assets = flutterManifest.assets;
|
||||
|
||||
expect(logger.errorText, contains('Asset manifest contains a null or empty uri.'));
|
||||
expect(assets.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('FlutterManifest with MemoryFileSystem', () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user