cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-plugin-file git commit: CB-8459 Fixes spec 111 failure due to incorrect relative paths handling
Date Wed, 11 Feb 2015 14:56:24 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 5cfe7a05b -> 64cf0fa3f


CB-8459 Fixes spec 111 failure due to incorrect relative paths handling


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/64cf0fa3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/64cf0fa3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/64cf0fa3

Branch: refs/heads/master
Commit: 64cf0fa3fde5f270e4bf1ca8a9e477241ea89774
Parents: 5cfe7a0
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Wed Feb 11 17:55:55 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Wed Feb 11 17:55:55 2015 +0300

----------------------------------------------------------------------
 src/windows/FileProxy.js | 20 +++++++++++++++++---
 tests/tests.js           |  5 +----
 2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/64cf0fa3/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 4148948..f62cdc8 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -96,10 +96,24 @@ function validName(name) {
     return !invalidNameRE.test(name.replace(driveRE,''));
 }
 
-var slashesRE = new RegExp('/{2,}','g');
-var parentRE = new RegExp('/([^/]+/)\\.\\.(/|$)','g');
 function sanitize(path) {
-    return path.replace(slashesRE,'/').replace(parentRE,'$2');
+    var slashesRE = new RegExp('/{2,}','g');
+    var components = path.replace(slashesRE, '/').split(/\/+/);
+    // Remove double dots, use old school array iteration instead of RegExp
+    // since it is impossible to debug them
+    for (var index = 0; index < components.length; ++index) {
+        if (components[index] === "..") {
+            components.splice(index, 1);
+            if (index > 0) {
+                // if we're not in the start of array then remove preceeding path component,
+                // In case if relative path points above the root directory, just ignore
double dots
+                // See file.spec.111 should not traverse above above the root directory for
test case
+                components.splice(index-1, 1);
+                --index;
+            }
+        }
+    }
+    return components.join('/');
 }
 
 var WinFS = function(name, root) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/64cf0fa3/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 1aa9d9c..5e3fe36 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -2734,10 +2734,7 @@ exports.defineAutoTests = function () {
                     create : false
                 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback,
it should not locate nonexistent file: ' + fileName), function (error) {
                     expect(error).toBeDefined();
-                    if (cordova.platformId == "windows8" || cordova.platformId == "windows")
-                        expect(error).toBeFileError(FileError.SECURITY_ERR);
-                    else
-                        expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
+                    expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
                     done();
                 });
             });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message