Unverified Commit b4274ef6 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

URL encode asset paths to support reserved characters in paths (#16046)

Fixes https://github.com/flutter/flutter/issues/14864
parent 29eebcbe
......@@ -214,7 +214,7 @@ abstract class CachingAssetBundle extends AssetBundle {
class PlatformAssetBundle extends CachingAssetBundle {
@override
Future<ByteData> load(String key) async {
final Uint8List encoded = utf8.encoder.convert(new Uri(path: key).path);
final Uint8List encoded = utf8.encoder.convert(new Uri(path: Uri.encodeFull(key)).path);
final ByteData asset =
await BinaryMessages.send('flutter/assets', encoded.buffer.asByteData());
if (asset == null)
......
......@@ -59,7 +59,7 @@ class FlutterManifest {
}
List<Uri> get assets {
return _flutterDescriptor['assets']?.map(Uri.parse)?.toList() ?? const <Uri>[];
return _flutterDescriptor['assets']?.map(Uri.encodeFull)?.map(Uri.parse)?.toList() ?? const <Uri>[];
}
List<Font> _fonts;
......
......@@ -69,7 +69,7 @@ $assetsSection
for (String packageName in packages) {
for (String asset in assets) {
final String entryKey = 'packages/$packageName/$asset';
final String entryKey = Uri.encodeFull('packages/$packageName/$asset');
expect(bundle.entries.containsKey(entryKey), true);
expect(
utf8.decode(await bundle.entries[entryKey].contentsAsBytes()),
......@@ -415,4 +415,29 @@ $assetsSection
);
});
});
testUsingContext('Asset paths can contain URL reserved characters', () async {
establishFlutterRoot();
writePubspecFile('pubspec.yaml', 'test');
writePackagesFile('test_package:p/p/lib/');
final List<String> assets = <String>['a/foo', 'a/foo[x]'];
writePubspecFile(
'p/p/pubspec.yaml',
'test_package',
assets: assets,
);
writeAssets('p/p/', assets);
const String expectedAssetManifest =
'{"packages/test_package/a/foo":["packages/test_package/a/foo"],'
'"packages/test_package/a/foo%5Bx%5D":["packages/test_package/a/foo%5Bx%5D"]}';
await buildAndVerifyAssets(
assets,
<String>['test_package'],
expectedAssetManifest,
);
});
}
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