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
26271223
Unverified
Commit
26271223
authored
Feb 07, 2020
by
Dan Field
Committed by
GitHub
Feb 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw when trying to load an empty file (#50325)
parent
f118b638
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
5 deletions
+44
-5
image_provider.dart
packages/flutter/lib/src/painting/image_provider.dart
+1
-1
image_provider_test.dart
packages/flutter/test/painting/image_provider_test.dart
+43
-4
No files found.
packages/flutter/lib/src/painting/image_provider.dart
View file @
26271223
...
@@ -746,7 +746,7 @@ class FileImage extends ImageProvider<FileImage> {
...
@@ -746,7 +746,7 @@ class FileImage extends ImageProvider<FileImage> {
final
Uint8List
bytes
=
await
file
.
readAsBytes
();
final
Uint8List
bytes
=
await
file
.
readAsBytes
();
if
(
bytes
.
lengthInBytes
==
0
)
if
(
bytes
.
lengthInBytes
==
0
)
return
null
;
throw
StateError
(
'
$file
is empty and cannot be loaded as an image.'
)
;
return
await
decode
(
bytes
);
return
await
decode
(
bytes
);
}
}
...
...
packages/flutter/test/painting/image_provider_test.dart
View file @
26271223
...
@@ -7,6 +7,7 @@ import 'dart:io';
...
@@ -7,6 +7,7 @@ import 'dart:io';
import
'dart:math'
as
math
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'dart:typed_data'
;
import
'package:file/memory.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/painting.dart'
;
import
'package:flutter/painting.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
@@ -22,11 +23,20 @@ void main() {
...
@@ -22,11 +23,20 @@ void main() {
return
PaintingBinding
.
instance
.
instantiateImageCodec
(
bytes
,
cacheWidth:
cacheWidth
,
cacheHeight:
cacheHeight
);
return
PaintingBinding
.
instance
.
instantiateImageCodec
(
bytes
,
cacheWidth:
cacheWidth
,
cacheHeight:
cacheHeight
);
};
};
group
(
ImageProvider
,
()
{
setUpAll
(()
{
setUpAll
(()
{
TestRenderingFlutterBinding
();
// initializes the imageCache
TestRenderingFlutterBinding
();
// initializes the imageCache
});
});
FlutterExceptionHandler
oldError
;
setUp
(()
{
oldError
=
FlutterError
.
onError
;
});
tearDown
(()
{
FlutterError
.
onError
=
oldError
;
});
group
(
'ImageProvider'
,
()
{
group
(
'Image cache'
,
()
{
group
(
'Image cache'
,
()
{
tearDown
(()
{
tearDown
(()
{
imageCache
.
clear
();
imageCache
.
clear
();
...
@@ -147,6 +157,21 @@ void main() {
...
@@ -147,6 +157,21 @@ void main() {
expect
(
uncaught
,
false
);
expect
(
uncaught
,
false
);
});
});
test
(
'File image with empty file throws expected error - (image cache)'
,
()
async
{
final
Completer
<
StateError
>
error
=
Completer
<
StateError
>();
FlutterError
.
onError
=
(
FlutterErrorDetails
details
)
{
print
(
details
.
exception
);
error
.
complete
(
details
.
exception
as
StateError
);
};
final
MemoryFileSystem
fs
=
MemoryFileSystem
();
final
File
file
=
fs
.
file
(
'/empty.png'
)..
createSync
(
recursive:
true
);
final
FileImage
provider
=
FileImage
(
file
);
provider
.
resolve
(
ImageConfiguration
.
empty
);
expect
(
await
error
.
future
,
isStateError
);
});
group
(
NetworkImage
,
()
{
group
(
NetworkImage
,
()
{
MockHttpClient
httpClient
;
MockHttpClient
httpClient
;
...
@@ -359,6 +384,20 @@ void main() {
...
@@ -359,6 +384,20 @@ void main() {
resizeImage
.
load
(
await
resizeImage
.
obtainKey
(
ImageConfiguration
.
empty
),
decode
);
resizeImage
.
load
(
await
resizeImage
.
obtainKey
(
ImageConfiguration
.
empty
),
decode
);
});
});
test
(
'File image with empty file throws expected error (load)'
,
()
async
{
final
Completer
<
StateError
>
error
=
Completer
<
StateError
>();
FlutterError
.
onError
=
(
FlutterErrorDetails
details
)
{
error
.
complete
(
details
.
exception
as
StateError
);
};
final
MemoryFileSystem
fs
=
MemoryFileSystem
();
final
File
file
=
fs
.
file
(
'/empty.png'
)..
createSync
(
recursive:
true
);
final
FileImage
provider
=
FileImage
(
file
);
expect
(
provider
.
load
(
provider
,
null
),
isA
<
MultiFrameImageStreamCompleter
>());
expect
(
await
error
.
future
,
isStateError
);
});
}
}
Future
<
Size
>
_resolveAndGetSize
(
ImageProvider
imageProvider
,
Future
<
Size
>
_resolveAndGetSize
(
ImageProvider
imageProvider
,
...
...
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