Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.13+7

* Returns an error when selected image data cannot be decoded.

## 0.8.13+6

* Replaces deprecated `kUTTypeGIF` with `UTTypeGIF` to fix iOS 15+ deprecation warnings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,44 @@ - (void)testFailingImageLoad API_AVAILABLE(ios(14)) {
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testUndecodableImageDataReturnsErrorAndFinishes API_AVAILABLE(ios(14)) {
NSData *undecodableImageData = [@"not an image" dataUsingEncoding:NSUTF8StringEncoding];

id mockItemProvider = OCMClassMock([NSItemProvider class]);
OCMStub([mockItemProvider hasItemConformingToTypeIdentifier:UTTypeImage.identifier])
.andReturn(YES);
[[mockItemProvider stub]
loadDataRepresentationForTypeIdentifier:UTTypeImage.identifier
completionHandler:[OCMArg invokeBlockWithArgs:undecodableImageData,
[NSNull null], nil]];

id pickerResult = OCMClassMock([PHPickerResult class]);
OCMStub([pickerResult itemProvider]).andReturn(mockItemProvider);

XCTestExpectation *errorExpectation = [self expectationWithDescription:@"invalid image error"];
XCTestExpectation *operationExpectation =
[self expectationWithDescription:@"Operation completed"];

FLTPHPickerSaveImageToPathOperation *operation = [[FLTPHPickerSaveImageToPathOperation alloc]
initWithResult:pickerResult
maxHeight:@100
maxWidth:@100
desiredImageQuality:@100
fullMetadata:YES
savedPathBlock:^(NSString *savedPath, FlutterError *error) {
XCTAssertNil(savedPath);
XCTAssertEqualObjects(error.code, @"invalid_image");
[errorExpectation fulfill];
}];
operation.completionBlock = ^{
[operationExpectation fulfill];
};

[operation start];
[self waitForExpectationsWithTimeout:30 handler:nil];
XCTAssertTrue(operation.isFinished);
}

- (void)testSavePNGImageWithoutFullMetadata API_AVAILABLE(ios(14)) {
id photoAssetUtil = OCMClassMock([PHAsset class]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ - (void)start {
/// Processes the image.
- (void)processImage:(NSData *)pickerImageData API_AVAILABLE(ios(14)) {
UIImage *localImage = [[UIImage alloc] initWithData:pickerImageData];
if (localImage == nil) {
FlutterError *flutterError = [FlutterError errorWithCode:@"invalid_image"
message:@"Could not decode image data."
details:nil];
[self completeOperationWithPath:nil error:flutterError];
return;
}

if (self.maxWidth != nil || self.maxHeight != nil) {
localImage = [FLTImagePickerImageUtil scaledImage:localImage
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker_ios
description: iOS implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.13+6
version: 0.8.13+7

environment:
sdk: ^3.10.0
Expand Down