[flutter_tools] use uri resolution for asset requests (#50844)
This commit is contained in:
parent
238dac141b
commit
3bb4ba61bd
@ -157,11 +157,9 @@ class WebAssetServer implements AssetReader {
|
|||||||
// If all of the lookups above failed, the file might have been an asset.
|
// If all of the lookups above failed, the file might have been an asset.
|
||||||
// Try and resolve the path relative to the built asset directory.
|
// Try and resolve the path relative to the built asset directory.
|
||||||
if (!file.existsSync()) {
|
if (!file.existsSync()) {
|
||||||
final String assetPath = requestPath.replaceFirst('/assets/', '');
|
final Uri potential = globals.fs.directory(getAssetBuildDirectory())
|
||||||
file = globals.fs.file(
|
.uri.resolve( requestPath.replaceFirst('/assets/', ''));
|
||||||
globals.fs.path.join(getAssetBuildDirectory(),
|
file = globals.fs.file(potential);
|
||||||
globals.fs.path.relative(assetPath)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.existsSync()) {
|
if (!file.existsSync()) {
|
||||||
|
@ -150,6 +150,20 @@ void main() {
|
|||||||
Platform: () => windows,
|
Platform: () => windows,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
test('serves asset files from in filesystem with url-encoded paths', () => testbed.run(() async {
|
||||||
|
final File source = globals.fs.file(globals.fs.path.join('build', 'flutter_assets', Uri.encodeFull('abcd象形字.png')))
|
||||||
|
..createSync(recursive: true)
|
||||||
|
..writeAsBytesSync(kTransparentImage);
|
||||||
|
final Response response = await webAssetServer
|
||||||
|
.handleRequest(Request('GET', Uri.parse('http://foobar/assets/abcd%25E8%25B1%25A1%25E5%25BD%25A2%25E5%25AD%2597.png')));
|
||||||
|
|
||||||
|
expect(response.headers, allOf(<Matcher>[
|
||||||
|
containsPair('content-length', source.lengthSync().toString()),
|
||||||
|
containsPair('content-type', 'image/png'),
|
||||||
|
]));
|
||||||
|
expect((await response.read().toList()).first, source.readAsBytesSync());
|
||||||
|
}));
|
||||||
|
|
||||||
test('serves asset files from in filesystem with known mime type on Windows', () => testbed.run(() async {
|
test('serves asset files from in filesystem with known mime type on Windows', () => testbed.run(() async {
|
||||||
final File source = globals.fs.file(globals.fs.path.join('build', 'flutter_assets', 'foo.png'))
|
final File source = globals.fs.file(globals.fs.path.join('build', 'flutter_assets', 'foo.png'))
|
||||||
..createSync(recursive: true)
|
..createSync(recursive: true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user