Repository: cordova-plugin-file Updated Branches: refs/heads/master 70247c066 -> ef93b58ce
CB-9891: Fix permission errors due to URI encoding inconsistency on Android 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/ef93b58c Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/ef93b58c Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/ef93b58c Branch: refs/heads/master Commit: ef93b58cecc433382f125702934e3ed30d995eb3 Parents: 70247c0 Author: Jason Ginchereau <jason...@microsoft.com> Authored: Wed Nov 11 12:05:32 2015 -0800 Committer: Jason Ginchereau <jason...@microsoft.com> Committed: Wed Nov 11 16:11:23 2015 -0800 ---------------------------------------------------------------------- www/android/FileSystem.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/ef93b58c/www/android/FileSystem.js ---------------------------------------------------------------------- diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js index 518e4c4..09b3b2d 100644 --- a/www/android/FileSystem.js +++ b/www/android/FileSystem.js @@ -23,14 +23,27 @@ FILESYSTEM_PROTOCOL = "cdvfile"; module.exports = { __format__: function(fullPath, nativeUrl) { - var path = '/' + this.name + '/' + encodeURI(fullPath); - path = path.replace('//','/'); - var ret = FILESYSTEM_PROTOCOL + '://localhost' + path; - var m = /\?.*/.exec(nativeUrl); - if (m) { - ret += m[0]; + var path; + var contentUrlMatch = /^content:\/\//.exec(nativeUrl); + if (contentUrlMatch) { + // When available, use the path from a native content URL, which was already encoded by Android. + // This is necessary because JavaScript's encodeURI() does not encode as many characters as + // Android, which can result in permission exceptions when the encoding of a content URI + // doesn't match the string for which permission was originally granted. + path = nativeUrl.substring(contentUrlMatch[0].length - 1); + } else { + path = encodeURI(fullPath); + if (!/^\//.test(path)) { + path = '/' + path; + } + + var m = /\?.*/.exec(nativeUrl); + if (m) { + path += m[0]; + } } - return ret; + + return FILESYSTEM_PROTOCOL + '://localhost/' + this.name + path; } }; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org