This is an automated email from the ASF dual-hosted git repository.

GitToTheHub pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f9f745  fix(ios): Use recommended `stringBy...` methods (#658)
6f9f745 is described below

commit 6f9f745d985286803b6f71aee100597798baf1f2
Author: Manuel Beck <[email protected]>
AuthorDate: Wed Sep 9 11:49:20 2026 +0200

    fix(ios): Use recommended `stringBy...` methods (#658)
    
    * fix(ios): Use recommended `stringBy...` methods
    
    - Instead using the deprecated 
`stringByReplacingPercentEscapesUsingEncoding` method use 
`stringByRemovingPercentEncoding` which is available since iOS 7
    - Instead using the deprecated `stringByAddingPercentEscapesUsingEncoding` 
method use `stringByAddingPercentEncodingWithAllowedCharacters:` with the 
parameter `[NSCharacterSet URLPathAllowedCharacterSet]` which is available 
since iOS 7
    
    * fix(ios): don't ecape `:` in `encodePath:``, add documentation
    
    - The iOS tests failed because the PR encodes a complete cdvfile: URI as 
though it were only a path. `:` would be encoded and would produce for 
e.g.`cdvfile%3A//localhost/bundle/`.
---
 src/ios/CDVFile.m            | 13 ++++++++++---
 src/ios/CDVLocalFilesystem.m |  9 ++++++++-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 62a77d1..8338c16 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -595,11 +595,18 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     [self.commandDelegate sendPluginResult:result 
callbackId:command.callbackId];
 }
 
-//encode path with percent escapes
+/**
+ * Encode a complete URI with percent escapes. Keep ':' unescaped so the
+ * cdvfile:// scheme remains recognizable after decoding an already-encoded 
URI.
+ */
 -(NSString *)encodePath:(NSString *)path
 {
-    NSString *decodedPath = [path 
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //decode 
incase it's already encoded to avoid encoding twice
-    return [decodedPath 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    NSString *decodedPath = [path stringByRemovingPercentEncoding]; //decode 
incase it's already encoded to avoid encoding twice
+    NSMutableCharacterSet *allowedCharacters = [[NSCharacterSet 
URLPathAllowedCharacterSet] mutableCopy];
+    // URLPathAllowedCharacterSet would escape the ':' in the URI scheme,
+    // so we add it back to the allowed characters.
+    [allowedCharacters addCharactersInString:@":"];
+    return [decodedPath 
stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
 }
 
 
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index c340ce0..e6c948d 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -122,10 +122,17 @@
     return [self filesystemPathForFullPath:url.fullPath];
 }
 
+/**
+ * CDVLocalFilesystem represents any registered local filesystem, such as
+ * temporary, persistent, documents, or bundle storage. Its public URL form is
+ * a cdvfile URI containing the filesystem name and the relative path.
+ * Escape the path before adding the cdvfile URI scheme and authority; the path
+ * must be encoded separately because it does not contain the URI scheme.
+ */
 - (CDVFilesystemURL *)URLforFullPath:(NSString *)fullPath
 {
     if (fullPath) {
-        NSString* escapedPath = [fullPath 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        NSString* escapedPath = [fullPath 
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet 
URLPathAllowedCharacterSet]];
         if ([fullPath hasPrefix:@"/"]) {
             return [CDVFilesystemURL fileSystemURLWithString:[NSString 
stringWithFormat:@"%@://localhost/%@%@", kCDVFilesystemURLPrefix, self.name, 
escapedPath]];
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to