From e14b7e539119010ade7aa4ab9f9af9ec2da0a1c8 Mon Sep 17 00:00:00 2001 From: FF Xu Date: Mon, 23 Mar 2015 02:16:56 +0800 Subject: [PATCH] CB-9840 Fallback file-transfer upload/download response encoding to latin1 in case not encoded with UTF-8 on iOS --- src/ios/CDVFileTransfer.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index aa60c52..45e83eb 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -569,6 +569,9 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) if (self.direction == CDV_TRANSFER_UPLOAD) { uploadResponse = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding]; + if (uploadResponse == nil) { + uploadResponse = [[NSString alloc] initWithData: self.responseData encoding:NSISOLatin1StringEncoding]; + } if ((self.responseCode >= 200) && (self.responseCode < 300)) { // create dictionary to return FileUploadResult object @@ -593,6 +596,10 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self.filePlugin makeEntryForURL:self.targetURL]]; } else { downloadResponse = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding]; + if (downloadResponse == nil) { + downloadResponse = [[NSString alloc] initWithData: self.responseData encoding:NSISOLatin1StringEncoding]; + } + CDVFileTransferError errorCode = self.responseCode == 404 ? FILE_NOT_FOUND_ERR : (self.responseCode == 304 ? NOT_MODIFIED : CONNECTION_ERR); result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[command createFileTransferError:errorCode AndSource:source AndTarget:target AndHttpStatus:self.responseCode AndBody:downloadResponse]];