From b08fb4050e9dc1b92f89c8c405f69662cab9b53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Panadero?= Date: Fri, 24 May 2019 14:15:52 +0200 Subject: [PATCH 1/3] Fixed ios file path encoding --- src/ios/FileOpener2.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 270b7ab..a2340a2 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; + NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; @@ -53,7 +53,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } dispatch_async(dispatch_get_main_queue(), ^{ - NSURL *fileURL = [NSURL URLWithString:[path stringByRemovingPercentEncoding]]; + NSURL *fileURL = [NSURL URLWithString:path]; localFile = fileURL.path; From 3517585d45fad6d2a08caa82b5d4b516427d6344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Panadero?= Date: Fri, 24 May 2019 14:28:37 +0200 Subject: [PATCH 2/3] Fixed ios file path encoding --- src/ios/FileOpener2.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index a2340a2..332d4da 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; + NSString *path = [command.arguments objectAtIndex:0]; NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; @@ -53,7 +53,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } dispatch_async(dispatch_get_main_queue(), ^{ - NSURL *fileURL = [NSURL URLWithString:path]; + NSURL *fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];; localFile = fileURL.path; From 01ac6a5d7dceae25cda3c525e1536bad48a19f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Panadero?= Date: Tue, 11 Jun 2019 10:36:41 +0200 Subject: [PATCH 3/3] Fixed iOS encoding if path parameter is already encoded --- src/ios/FileOpener2.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 332d4da..465b2a4 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -53,7 +53,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } dispatch_async(dispatch_get_main_queue(), ^{ - NSURL *fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];; + NSURL *fileURL = NULL; + NSString *decodedPath = [path stringByRemovingPercentEncoding]; + if ([path isEqualToString:decodedPath]) { + NSLog(@"Path parameter not encoded. Building file URL encoding it..."); + fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];; + } else { + NSLog(@"Path parameter already encoded. Building file URL without encoding it..."); + fileURL = [NSURL URLWithString:path]; + } localFile = fileURL.path;