CB-6012: Preserve query parameters in cdvfile:// urls; strip query params from 
local filesystem urls when searching for files


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

Branch: refs/heads/master
Commit: 5294f27a3b67224d172bf9fdbe3ac5bb3af61929
Parents: f24abdd
Author: Ian Clelland <[email protected]>
Authored: Tue Feb 11 11:55:28 2014 -0500
Committer: Ian Clelland <[email protected]>
Committed: Tue Feb 11 14:11:27 2014 -0500

----------------------------------------------------------------------
 RELEASENOTES.md                     |  1 +
 src/android/LocalFilesystem.java    |  6 +++++-
 src/android/LocalFilesystemURL.java |  3 +++
 src/ios/CDVFile.m                   |  3 +++
 src/ios/CDVLocalFilesystem.m        | 13 +++++++++++--
 5 files changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5294f27a/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 6fbdff7..3c2eae5 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -128,3 +128,4 @@
 ### 1.0.1
 * CB-5959: Entry.getMetadata should return size attribute
 * CB-6010: Test properly for presence of URLforFilesystemPath method
+* CB-6012: Preserve query strings on cdvfile:// URLs where necessary

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5294f27a/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 329eac7..bc17772 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -35,6 +35,10 @@ public class LocalFilesystem extends Filesystem {
        @Override
        public String filesystemPathForURL(LocalFilesystemURL url) {
            String path = new File(this.fsRoot, url.fullPath).toString();
+        int questionMark = path.indexOf("?");
+        if (questionMark >= 0) {
+          path = path.substring(0, questionMark);
+        }
            if (path.endsWith("/")) {
              path = path.substring(0, path.length()-1);
            }
@@ -106,7 +110,7 @@ public class LocalFilesystem extends Filesystem {
 
        @Override
        public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) 
throws IOException {
-      File fp = new File(this.fsRoot, inputURL.fullPath);
+      File fp = new File(filesystemPathForURL(inputURL));
 
       if (!fp.exists()) {
           throw new FileNotFoundException();

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5294f27a/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java 
b/src/android/LocalFilesystemURL.java
index 808fc20..8583a8f 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -21,6 +21,9 @@ public class LocalFilesystemURL {
        private String fullPathForLocalURL(Uri URL) {
                if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && 
"localhost".equals(URL.getHost())) {
                        String path = URL.getPath();
+            if (URL.getQuery() != null) {
+                path = path + "?" + URL.getQuery();
+            }
                        return path.substring(path.indexOf('/', 1));
                } else if ("content".equals(URL.getScheme())) {
                        return '/' + URL.getHost() + URL.getPath();

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5294f27a/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index a4347bc..9c915e9 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -86,6 +86,9 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 {
     if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] 
isEqualToString:@"localhost"]) {
         NSString *path = [uri path];
+        if ([uri query]) {
+            path = [NSString stringWithFormat:@"%@?%@", path, [uri query]];
+        }
         NSRange slashRange = [path rangeOfString:@"/" options:0 
range:NSMakeRange(1, path.length-1)];
         if (slashRange.location == NSNotFound) {
             return @"";

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5294f27a/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index f80d1fa..e7208b4 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -69,7 +69,7 @@
 - (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString 
*)fsName isDirectory:(BOOL)isDir
 {
     NSMutableDictionary* dirEntry = [NSMutableDictionary 
dictionaryWithCapacity:5];
-    NSString* lastPart = [fullPath lastPathComponent];
+    NSString* lastPart = [[self stripQueryParametersFromPath:fullPath] 
lastPathComponent];
     if (isDir && ![fullPath hasSuffix:@"/"]) {
         fullPath = [fullPath stringByAppendingString:@"/"];
     }
@@ -83,6 +83,15 @@
     return dirEntry;
 }
 
+- (NSString *)stripQueryParametersFromPath:(NSString *)fullPath
+{
+    NSRange questionMark = [fullPath rangeOfString:@"?"];
+    if (questionMark.location != NSNotFound) {
+        return [fullPath 
substringWithRange:NSMakeRange(0,questionMark.location)];
+    }
+    return fullPath;
+}
+
 /*
  * IN
  *  NSString localURI
@@ -95,7 +104,7 @@
 - (NSString *)filesystemPathForURL:(CDVFilesystemURL *)url
 {
     NSString *path = nil;
-    NSString *fullPath = url.fullPath;
+    NSString *fullPath = [self stripQueryParametersFromPath:url.fullPath];
     path = [NSString stringWithFormat:@"%@%@", self.fsRoot, fullPath];
     if ([path hasSuffix:@"/"]) {
       path = [path substringToIndex:([path length]-1)];

Reply via email to