Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f8c9f72b
Unverified
Commit
f8c9f72b
authored
Oct 01, 2022
by
Andrew Kolos
Committed by
GitHub
Oct 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
URI-decode asset paths before writing them to the asset manifest (#112415)
parent
ecdfa953
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
74 deletions
+61
-74
image_resolution_test.dart
packages/flutter/test/painting/image_resolution_test.dart
+1
-3
asset.dart
packages/flutter_tools/lib/src/asset.dart
+6
-1
asset_bundle_package_test.dart
...r_tools/test/general.shard/asset_bundle_package_test.dart
+2
-2
asset_bundle_variant_test.dart
...r_tools/test/general.shard/asset_bundle_variant_test.dart
+52
-68
No files found.
packages/flutter/test/painting/image_resolution_test.dart
View file @
f8c9f72b
...
...
@@ -105,14 +105,12 @@ void main() {
bundle:
testAssetBundle
,
);
// we have the exact match for this scale, let's use it
assetImage
.
obtainKey
(
ImageConfiguration
.
empty
)
.
then
(
expectAsync1
((
AssetBundleImageKey
bundleKey
)
{
expect
(
bundleKey
.
name
,
mainAssetPath
);
expect
(
bundleKey
.
scale
,
1.0
);
}));
// we also have the exact match for this scale, let's use it
assetImage
.
obtainKey
(
ImageConfiguration
(
bundle:
testAssetBundle
,
devicePixelRatio:
3.0
,
...
...
@@ -122,7 +120,7 @@ void main() {
}));
});
test
(
'When high-res device and high-res asset not present in bundle then
return main variant'
,
()
{
test
(
'When high-res device and high-res asset not present in bundle then return main variant'
,
()
{
const
String
mainAssetPath
=
'assets/normalFolder/normalFile.png'
;
final
Map
<
String
,
List
<
String
>>
assetBundleMap
=
...
...
packages/flutter_tools/lib/src/asset.dart
View file @
f8c9f72b
...
...
@@ -644,7 +644,12 @@ class ManifestAssetBundle implements AssetBundle {
final
List
<
_Asset
>
sortedKeys
=
jsonEntries
.
keys
.
toList
()
..
sort
((
_Asset
left
,
_Asset
right
)
=>
left
.
entryUri
.
path
.
compareTo
(
right
.
entryUri
.
path
));
for
(
final
_Asset
main
in
sortedKeys
)
{
jsonObject
[
main
.
entryUri
.
path
]
=
jsonEntries
[
main
]!;
final
String
decodedEntryPath
=
Uri
.
decodeFull
(
main
.
entryUri
.
path
);
final
List
<
String
>
rawEntryVariantsPaths
=
jsonEntries
[
main
]!;
final
List
<
String
>
decodedEntryVariantPaths
=
rawEntryVariantsPaths
.
map
((
String
value
)
=>
Uri
.
decodeFull
(
value
))
.
toList
();
jsonObject
[
decodedEntryPath
]
=
decodedEntryVariantPaths
;
}
return
DevFSStringContent
(
json
.
encode
(
jsonObject
));
}
...
...
packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
View file @
f8c9f72b
...
...
@@ -447,7 +447,7 @@ $assetsSection
writePubspecFile
(
'pubspec.yaml'
,
'test'
);
writePackagesFile
(
'test_package:p/p/lib/'
);
final
List
<
String
>
assets
=
<
String
>[
'a/foo'
,
'a/foo[x]'
];
final
List
<
String
>
assets
=
<
String
>[
'a/foo'
,
'a/foo
[x]'
];
writePubspecFile
(
'p/p/pubspec.yaml'
,
'test_package'
,
...
...
@@ -457,7 +457,7 @@ $assetsSection
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
"]}'
;
'"packages/test_package/a/foo
[x]":["packages/test_package/a/foo [x]
"]}'
;
await
buildAndVerifyAssets
(
assets
,
...
...
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
View file @
f8c9f72b
...
...
@@ -30,11 +30,11 @@ void main() {
return
parsedManifest
;
}
group
(
'AssetBundle asset variants (with
POSIX
-style paths)'
,
()
{
late
final
Platform
platform
;
late
final
FileSystem
fs
;
group
(
'AssetBundle asset variants (with
Unix
-style paths)'
,
()
{
late
Platform
platform
;
late
FileSystem
fs
;
setUp
All
(()
{
setUp
(()
{
platform
=
FakePlatform
();
fs
=
MemoryFileSystem
.
test
();
Cache
.
flutterRoot
=
Cache
.
defaultFlutterRoot
(
...
...
@@ -87,10 +87,10 @@ flutter:
);
final
Map
<
String
,
List
<
String
>>
manifest
=
await
extractAssetManifestFromBundle
(
bundle
);
final
List
<
String
>
variantsForImage
=
manifest
[
image
]!;
expect
(
variantsForImage
,
contains
(
image2xVariant
));
expect
(
variantsForImage
,
isNot
(
contains
(
imageNonVariant
)));
expect
(
manifest
,
hasLength
(
2
));
expect
(
manifest
[
image
],
equals
(<
String
>[
image
,
image2xVariant
]));
expect
(
manifest
[
imageNonVariant
],
equals
(<
String
>[
imageNonVariant
]));
});
testWithoutContext
(
'Asset directories are recursively searched for assets'
,
()
async
{
...
...
@@ -122,11 +122,40 @@ flutter:
);
final
Map
<
String
,
List
<
String
>>
manifest
=
await
extractAssetManifestFromBundle
(
bundle
);
expect
(
manifest
,
contains
(
secondLevelImage
));
expect
(
manifest
,
contains
(
topLevelImage
));
expect
(
manifest
[
secondLevelImage
],
hasLength
(
2
));
expect
(
manifest
[
secondLevelImage
],
contains
(
secondLevelImage
));
expect
(
manifest
[
secondLevelImage
],
contains
(
secondLevel2xVariant
));
expect
(
manifest
,
hasLength
(
2
));
expect
(
manifest
[
topLevelImage
],
equals
(<
String
>[
topLevelImage
]));
expect
(
manifest
[
secondLevelImage
],
equals
(<
String
>[
secondLevelImage
,
secondLevel2xVariant
]));
});
testWithoutContext
(
'Asset paths should never be URI-encoded'
,
()
async
{
const
String
image
=
'assets/normalFolder/i have URI-reserved_characters.jpg'
;
const
String
imageVariant
=
'assets/normalFolder/3x/i have URI-reserved_characters.jpg'
;
final
List
<
String
>
assets
=
<
String
>[
image
,
imageVariant
];
for
(
final
String
asset
in
assets
)
{
final
File
assetFile
=
fs
.
file
(
asset
);
assetFile
.
createSync
(
recursive:
true
);
assetFile
.
writeAsStringSync
(
asset
);
}
final
ManifestAssetBundle
bundle
=
ManifestAssetBundle
(
logger:
BufferLogger
.
test
(),
fileSystem:
fs
,
platform:
platform
,
);
await
bundle
.
build
(
packagesPath:
'.packages'
,
flutterProject:
FlutterProject
.
fromDirectoryTest
(
fs
.
currentDirectory
),
);
final
Map
<
String
,
List
<
String
>>
manifest
=
await
extractAssetManifestFromBundle
(
bundle
);
expect
(
manifest
,
hasLength
(
1
));
expect
(
manifest
[
image
],
equals
(<
String
>[
image
,
imageVariant
]));
});
});
...
...
@@ -135,13 +164,7 @@ flutter:
late
final
Platform
platform
;
late
final
FileSystem
fs
;
String
correctPathSeparators
(
String
path
)
{
// The in-memory file system is strict about slashes on Windows being the
// correct way. See https://github.com/google/file.dart/issues/112.
return
path
.
replaceAll
(
'/'
,
fs
.
path
.
separator
);
}
setUpAll
(()
{
setUp
(()
{
platform
=
FakePlatform
(
operatingSystem:
'windows'
);
fs
=
MemoryFileSystem
.
test
(
style:
FileSystemStyle
.
windows
);
Cache
.
flutterRoot
=
Cache
.
defaultFlutterRoot
(
...
...
@@ -165,19 +188,16 @@ flutter:
);
});
testWithoutContext
(
'Only images in folders named with device pixel ratios (e.g. 2x, 3.0x) should be considered as variants of other images'
,
()
async
{
const
String
image
=
'assets/image.jpg'
;
const
String
image2xVariant
=
'assets/2x/image.jpg'
;
const
String
imageNonVariant
=
'assets/notAVariant/image.jpg'
;
final
List
<
String
>
assets
=
<
String
>[
image
,
image2xVariant
,
imageNonVariant
testWithoutContext
(
'Variant detection works with windows-style filepaths'
,
()
async
{
const
List
<
String
>
assets
=
<
String
>[
r'assets\foo.jpg'
,
r'assets\2x\foo.jpg'
,
r'assets\somewhereElse\bar.jpg'
,
r'assets\somewhereElse\2x\bar.jpg'
,
];
for
(
final
String
asset
in
assets
)
{
final
File
assetFile
=
fs
.
file
(
correctPathSeparators
(
asset
)
);
final
File
assetFile
=
fs
.
file
(
asset
);
assetFile
.
createSync
(
recursive:
true
);
assetFile
.
writeAsStringSync
(
asset
);
}
...
...
@@ -194,46 +214,10 @@ flutter:
);
final
Map
<
String
,
List
<
String
>>
manifest
=
await
extractAssetManifestFromBundle
(
bundle
);
final
List
<
String
>
variantsForImage
=
manifest
[
image
]!;
expect
(
variantsForImage
,
contains
(
image2xVariant
));
expect
(
variantsForImage
,
isNot
(
contains
(
imageNonVariant
)));
});
testWithoutContext
(
'Asset directories are recursively searched for assets'
,
()
async
{
const
String
topLevelImage
=
'assets/image.jpg'
;
const
String
secondLevelImage
=
'assets/folder/secondLevel.jpg'
;
const
String
secondLevel2xVariant
=
'assets/folder/2x/secondLevel.jpg'
;
final
List
<
String
>
assets
=
<
String
>[
topLevelImage
,
secondLevelImage
,
secondLevel2xVariant
];
for
(
final
String
asset
in
assets
)
{
final
File
assetFile
=
fs
.
file
(
correctPathSeparators
(
asset
));
assetFile
.
createSync
(
recursive:
true
);
assetFile
.
writeAsStringSync
(
asset
);
}
final
ManifestAssetBundle
bundle
=
ManifestAssetBundle
(
logger:
BufferLogger
.
test
(),
fileSystem:
fs
,
platform:
platform
,
);
await
bundle
.
build
(
packagesPath:
'.packages'
,
flutterProject:
FlutterProject
.
fromDirectoryTest
(
fs
.
currentDirectory
),
);
final
Map
<
String
,
List
<
String
>>
manifest
=
await
extractAssetManifestFromBundle
(
bundle
);
expect
(
manifest
,
contains
(
secondLevelImage
));
expect
(
manifest
,
contains
(
topLevelImage
));
expect
(
manifest
[
secondLevelImage
],
hasLength
(
2
));
expect
(
manifest
[
secondLevelImage
],
contains
(
secondLevelImage
));
expect
(
manifest
[
secondLevelImage
],
contains
(
secondLevel2xVariant
));
expect
(
manifest
,
hasLength
(
2
));
expect
(
manifest
[
'assets/foo.jpg'
],
equals
(<
String
>[
'assets/foo.jpg'
,
'assets/2x/foo.jpg'
]));
expect
(
manifest
[
'assets/somewhereElse/bar.jpg'
],
equals
(<
String
>[
'assets/somewhereElse/bar.jpg'
,
'assets/somewhereElse/2x/bar.jpg'
]));
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment