Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 44df96f09 -> 59733c24e


CB-8497 Fix handling of file paths with # character

Because # is a valid filename character, it must be encoded whenever it
is in a path that is part of a URI, to prevent part of the path from
being parsed as a URI fragment.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/c9fcd3c5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/c9fcd3c5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/c9fcd3c5

Branch: refs/heads/master
Commit: c9fcd3c534b7271bcbd145aa927698894d55ec47
Parents: ef93b58
Author: Jason Ginchereau <[email protected]>
Authored: Thu Nov 12 17:59:21 2015 -0800
Committer: Jason Ginchereau <[email protected]>
Committed: Fri Nov 13 10:23:27 2015 -0800

----------------------------------------------------------------------
 src/windows/FileProxy.js                  |  8 ++++----
 tests/tests.js                            | 15 +++++++++++++++
 www/FileSystem.js                         |  7 +++++++
 www/android/FileSystem.js                 |  2 +-
 www/blackberry10/FileSystem.js            |  8 ++++----
 www/blackberry10/createEntryFromNative.js |  8 +++-----
 www/browser/FileSystem.js                 |  2 +-
 www/firefoxos/FileSystem.js               |  2 +-
 www/ios/FileSystem.js                     |  2 +-
 www/osx/FileSystem.js                     |  2 +-
 www/ubuntu/FileSystem.js                  |  2 +-
 11 files changed, 39 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 2192416..11604f5 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -154,7 +154,7 @@ var WinFS = function(name, root) {
         this.winpath += "/";
     }
     this.makeNativeURL = function(path) {
-        return encodeURI(this.root.nativeURL + 
sanitize(path.replace(':','%3A')));};
+        return FileSystem.encodeURIPath(this.root.nativeURL + 
sanitize(path.replace(':','%3A')));};
     root.fullPath = '/';
     if (!root.nativeURL)
             root.nativeURL = 'file://'+sanitize(this.winpath + 
root.fullPath).replace(':','%3A');
@@ -164,7 +164,7 @@ var WinFS = function(name, root) {
 utils.extend(WinFS, FileSystem);
 
 WinFS.prototype.__format__ = function(fullPath) {
-    var path = 
sanitize('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath));
+    var path = 
sanitize('/'+this.name+(fullPath[0]==='/'?'':'/')+FileSystem.encodeURIPath(fullPath));
     return 'cdvfile://localhost' + path;
 };
 
@@ -234,7 +234,7 @@ function getFilesystemFromPath(path) {
 var msapplhRE = new RegExp('^ms-appdata://localhost/');
 function pathFromURL(url) {
     url=url.replace(msapplhRE,'ms-appdata:///');
-    var path = decodeURI(url);
+    var path = decodeURIComponent(url);
     // support for file name with parameters
     if (/\?/g.test(path)) {
         path = String(path).split("?")[0];
@@ -256,7 +256,7 @@ function pathFromURL(url) {
         }
     });
     
-    return path.replace('%3A',':').replace(driveRE,'$1');
+    return path.replace(driveRE,'$1');
 }
 
 function getFilesystemFromURL(url) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 618073a..432febe 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -1156,6 +1156,21 @@ exports.defineAutoTests = function () {
                     }, failed.bind(null, done, 'entry.remove - Error removing 
entry : ' + fileName));
                 }, failed.bind(null, done, 'createFile - Error creating file : 
' + fileName));
             });
+            it("file.spec.53.1 Entry.remove on filename with #s", function 
(done) {
+                var fileName = "entry.#rm#.file";
+                // create a new file entry
+                createFile(fileName, function (entry) {
+                    expect(entry).toBeDefined();
+                    entry.remove(function () {
+                        root.getFile(fileName, null, succeed.bind(null, done, 
'root.getFile - Unexpected success callback, it should not get deleted file : ' 
+ fileName), function (error) {
+                            expect(error).toBeDefined();
+                            
expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
+                            // cleanup
+                            deleteEntry(fileName, done);
+                        });
+                    }, failed.bind(null, done, 'entry.remove - Error removing 
entry : ' + fileName));
+                }, failed.bind(null, done, 'createFile - Error creating file : 
' + fileName));
+            });
             it("file.spec.54 remove on empty directory", function (done) {
                 var dirName = "entry.rm.dir";
                 // create a new directory entry

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/FileSystem.js b/www/FileSystem.js
index 36bffbb..907e585 100644
--- a/www/FileSystem.js
+++ b/www/FileSystem.js
@@ -45,4 +45,11 @@ FileSystem.prototype.toJSON = function() {
     return "<FileSystem: " + this.name + ">";
 };
 
+// Use instead of encodeURI() when encoding just the path part of a URI rather 
than an entire URI.
+FileSystem.encodeURIPath = function(path) {
+    // Because # is a valid filename character, it must be encoded to prevent 
part of the
+    // path from being parsed as a URI fragment.
+    return encodeURI(path).replace(/#/g, '%23');
+}
+
 module.exports = FileSystem;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/android/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js
index 09b3b2d..b16333b 100644
--- a/www/android/FileSystem.js
+++ b/www/android/FileSystem.js
@@ -32,7 +32,7 @@ module.exports = {
             // doesn't match the string for which permission was originally 
granted.
             path = nativeUrl.substring(contentUrlMatch[0].length - 1);
         } else {
-            path = encodeURI(fullPath);
+            path = FileSystem.encodeURIPath(fullPath);
             if (!/^\//.test(path)) {
                 path = '/' + path;
             }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/blackberry10/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/FileSystem.js b/www/blackberry10/FileSystem.js
index 3345452..518a9aa 100644
--- a/www/blackberry10/FileSystem.js
+++ b/www/blackberry10/FileSystem.js
@@ -31,16 +31,16 @@ module.exports = {
     __format__: function(fullPath) {
         switch (this.name) {
             case 'temporary':
-                path = info.temporaryPath + fullPath;
+                path = info.temporaryPath + FileSystem.encodeURIPath(fullPath);
                 break;
             case 'persistent':
-                path = info.persistentPath + fullPath;
+                path = info.persistentPath + 
FileSystem.encodeURIPath(fullPath);
                 break;
             case 'root':
-                path = 'file://' + fullPath;
+                path = 'file://' + FileSystem.encodeURIPath(fullPath);
                 break;
         }
-        return window.encodeURI(path);
+        return path;
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/blackberry10/createEntryFromNative.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/createEntryFromNative.js 
b/www/blackberry10/createEntryFromNative.js
index 21e612f..7202e3a 100644
--- a/www/blackberry10/createEntryFromNative.js
+++ b/www/blackberry10/createEntryFromNative.js
@@ -45,11 +45,11 @@ module.exports = function (native) {
         temporaryPath = info.temporaryPath.substring(7);
     //fix bb10 webkit incorrect nativeURL
     if (native.filesystem.name === 'root') {
-        entry.nativeURL = 'file:///' + native.fullPath;
+        entry.nativeURL = 'file:///' + 
FileSystem.encodeURIPath(native.fullPath);
     } else if (entry.nativeURL.indexOf('filesystem:local:///persistent/') === 
0) {
-        entry.nativeURL = info.persistentPath + native.fullPath;
+        entry.nativeURL = info.persistentPath + 
FileSystem.encodeURIPath(native.fullPath);
     } else if (entry.nativeURL.indexOf('filesystem:local:///temporary') === 0) 
{
-        entry.nativeURL = info.temporaryPath + native.fullPath;
+        entry.nativeURL = info.temporaryPath + 
FileSystem.encodeURIPath(native.fullPath);
     }
     //translate file system name from bb10 webkit
     if (entry.filesystemName === 'local__0:Persistent' || 
entry.fullPath.indexOf(persistentPath) !== -1) {
@@ -71,7 +71,5 @@ module.exports = function (native) {
     if (entry.isDirectory && entry.nativeURL.substring(entry.nativeURL.length 
- 1) !== '/') {
         entry.nativeURL += '/';
     }
-    //encode URL
-    entry.nativeURL = window.encodeURI(entry.nativeURL);
     return entry;
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/browser/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/browser/FileSystem.js b/www/browser/FileSystem.js
index 27373d1..c0996cb 100644
--- a/www/browser/FileSystem.js
+++ b/www/browser/FileSystem.js
@@ -25,7 +25,7 @@ FILESYSTEM_PREFIX = "file:///";
 
 module.exports = {
     __format__: function(fullPath) {
-        return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : 
'/') + encodeURI(fullPath));
+        return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : 
'/') + FileSystem.encodeURIPath(fullPath));
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/firefoxos/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/firefoxos/FileSystem.js b/www/firefoxos/FileSystem.js
index 8ff0ec4..edc003b 100644
--- a/www/firefoxos/FileSystem.js
+++ b/www/firefoxos/FileSystem.js
@@ -23,7 +23,7 @@ FILESYSTEM_PREFIX = "file:///";
 
 module.exports = {
     __format__: function(fullPath) {
-        return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : 
'/') + encodeURI(fullPath));
+        return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : 
'/') + FileSystem.encodeURIPath(fullPath));
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/ios/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/ios/FileSystem.js b/www/ios/FileSystem.js
index b11d58f..114ebb0 100644
--- a/www/ios/FileSystem.js
+++ b/www/ios/FileSystem.js
@@ -23,7 +23,7 @@ FILESYSTEM_PROTOCOL = "cdvfile";
 
 module.exports = {
     __format__: function(fullPath) {
-        var path = 
('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
+        var path = 
('/'+this.name+(fullPath[0]==='/'?'':'/')+FileSystem.encodeURIPath(fullPath)).replace('//','/');
         return FILESYSTEM_PROTOCOL + '://localhost' + path;
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/osx/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/osx/FileSystem.js b/www/osx/FileSystem.js
index b11d58f..114ebb0 100644
--- a/www/osx/FileSystem.js
+++ b/www/osx/FileSystem.js
@@ -23,7 +23,7 @@ FILESYSTEM_PROTOCOL = "cdvfile";
 
 module.exports = {
     __format__: function(fullPath) {
-        var path = 
('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
+        var path = 
('/'+this.name+(fullPath[0]==='/'?'':'/')+FileSystem.encodeURIPath(fullPath)).replace('//','/');
         return FILESYSTEM_PROTOCOL + '://localhost' + path;
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c9fcd3c5/www/ubuntu/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/ubuntu/FileSystem.js b/www/ubuntu/FileSystem.js
index c43da82..3594565 100644
--- a/www/ubuntu/FileSystem.js
+++ b/www/ubuntu/FileSystem.js
@@ -26,7 +26,7 @@ module.exports = {
         if (this.name === 'content') {
             return 'content:/' + fullPath;
         }
-        var path = ('/' + this.name + (fullPath[0] === '/' ? '' : '/') + 
encodeURI(fullPath)).replace('//','/');
+        var path = ('/' + this.name + (fullPath[0] === '/' ? '' : '/') + 
FileSystem.encodeURIPath(fullPath)).replace('//','/');
 
         return FILESYSTEM_PROTOCOL + '://localhost' + path;
     }


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

Reply via email to