CB-6116: Fix error where resolveLocalFileSystemURL would fail to parse file://localhost/<path> URLs
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/eafcdc42 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/eafcdc42 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/eafcdc42 Branch: refs/heads/master Commit: eafcdc425c0499286cef2f4eda166a1ee594dea8 Parents: 5e1e20a Author: Ian Clelland <[email protected]> Authored: Fri Feb 28 14:34:27 2014 -0500 Committer: Ian Clelland <[email protected]> Committed: Fri Feb 28 14:52:29 2014 -0500 ---------------------------------------------------------------------- src/android/FileUtils.java | 12 ++++++++++-- src/ios/CDVFile.m | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eafcdc42/src/android/FileUtils.java ---------------------------------------------------------------------- diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java index caaf573..4da8a77 100644 --- a/src/android/FileUtils.java +++ b/src/android/FileUtils.java @@ -525,10 +525,18 @@ public class FileUtils extends CordovaPlugin { /* This looks like a file url. Get the path, and see if any handlers recognize it. */ String path; int questionMark = decoded.indexOf("?"); + int pathEnd; if (questionMark < 0) { - path = decoded.substring(7, decoded.length()); + pathEnd = decoded.length(); } else { - path = decoded.substring(7, questionMark); + pathEnd = questionMark; + } + + int thirdSlash = decoded.indexOf("/", 7); + if (thirdSlash < 0 || thirdSlash > pathEnd) { + path = ""; + } else { + path = decoded.substring(thirdSlash, pathEnd); } inputURL = this.filesystemURLforLocalPath(path); } else { http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eafcdc42/src/ios/CDVFile.m ---------------------------------------------------------------------- diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m index dfda68b..fa4a0a2 100644 --- a/src/ios/CDVFile.m +++ b/src/ios/CDVFile.m @@ -428,10 +428,17 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; /* This looks like a file url. Get the path, and see if any handlers recognize it. */ NSString* path; NSRange questionMark = [localURIstr rangeOfString:@"?"]; + NSUInteger pathEnd; if (questionMark.location == NSNotFound) { - path = [localURIstr substringFromIndex:7]; + pathEnd = localURIstr.length; } else { - path = [localURIstr substringWithRange:NSMakeRange(7,questionMark.location-7)]; + pathEnd = questionMark.location; + } + NSRange thirdSlash = [localURIstr rangeOfString:@"/" options:0 range:(NSRange){7, pathEnd-7}]; + if (thirdSlash.location == NSNotFound) { + path = @""; + } else { + path = [localURIstr substringWithRange:NSMakeRange(thirdSlash.location, pathEnd-thirdSlash.location)]; } inputURI = [self fileSystemURLforLocalPath:path]; } else {
