You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/07/02 16:41:06 UTC

git commit: CB-6571 Fix getParentForLocalURL to work correctly with directories with trailing '/' (This closes #58)

Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 0dba6b4f2 -> 56f1f3d6b


CB-6571 Fix getParentForLocalURL to work correctly with directories with trailing '/' (This closes #58)

Fixes 2 failing unit tests in mobile spec.


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

Branch: refs/heads/master
Commit: 56f1f3d6bb4493c026e4a603947b4ea3e4ab0975
Parents: 0dba6b4
Author: Martin Bektchiev <ma...@telerik.com>
Authored: Mon Jun 30 18:21:08 2014 +0300
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jul 2 10:40:14 2014 -0400

----------------------------------------------------------------------
 src/android/Filesystem.java      | 6 +++---
 src/android/LocalFilesystem.java | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/56f1f3d6/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index af74aae..bbdeb0b 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -42,7 +42,7 @@ public abstract class Filesystem {
         JSONObject entry = new JSONObject();
 
         int end = path.endsWith("/") ? 1 : 0;
-        String[] parts = path.substring(0,path.length()-end).split("/");
+        String[] parts = path.substring(0,path.length()-end).split("/+");
         String fileName = parts[parts.length-1];
         entry.put("isFile", !isDir);
         entry.put("isDirectory", isDir);
@@ -82,8 +82,8 @@ public abstract class Filesystem {
 		LocalFilesystemURL newURL = new LocalFilesystemURL(inputURL.URL);
 	
 		if (!("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath))) {
-			int end = inputURL.fullPath.endsWith("/") ? 1 : 0;
-	        int lastPathStartsAt = inputURL.fullPath.lastIndexOf('/', inputURL.fullPath.length()-end)+1;
+			String dirURL = inputURL.fullPath.replaceAll("/+$", "");
+			int lastPathStartsAt = dirURL.lastIndexOf('/')+1;
 			newURL.fullPath = newURL.fullPath.substring(0,lastPathStartsAt);
 		}
 		return getEntryForLocalURL(newURL);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/56f1f3d6/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 41bd427..e70ee22 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -96,7 +96,7 @@ public class LocalFilesystem extends Filesystem {
 	    if (isAbsolutePath) {
 	        rawPath = rawPath.substring(1);
 	    }
-	    ArrayList<String> components = new ArrayList<String>(Arrays.asList(rawPath.split("/")));
+	    ArrayList<String> components = new ArrayList<String>(Arrays.asList(rawPath.split("/+")));
 	    for (int index = 0; index < components.size(); ++index) {
 	        if (components.get(index).equals("..")) {
 	            components.remove(index);