From 4207f919460d898e7895a1972084b6b226df079a Mon Sep 17 00:00:00 2001 From: Pawel Andruszkiewicz Date: Mon, 9 Nov 2015 10:21:53 +0100 Subject: [PATCH] [File] Improved error reporting for DirectoryEntry. [Verification] Code compiles, pass rate: 101/140. Change-Id: Ia84f40dc87f185abf1da67bf712383d28b1bbd8b Signed-off-by: Pawel Andruszkiewicz --- src/file/js/DirectoryEntry.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/file/js/DirectoryEntry.js b/src/file/js/DirectoryEntry.js index ee53ec8..0d442b4 100644 --- a/src/file/js/DirectoryEntry.js +++ b/src/file/js/DirectoryEntry.js @@ -47,11 +47,22 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp var parent_path = absolute_path.substring(0, absolute_path.lastIndexOf('/')); var child_name = absolute_path.substring(absolute_path.lastIndexOf('/') + 1); + // http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions + var disallowedCharacters = [ '/', '\\', '<', '>', ':', '?', '*', '"', '|' ]; + + for (var i = 0; i < disallowedCharacters.length; ++i) { + if (-1 !== child_name.indexOf(disallowedCharacters[i])) { + console.error('File name contains disallowed character: ' + disallowedCharacters[i]); + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + } + var resolveSuccess = function(dir) { // absolute_path points to existing destination if (create_flag && exclusive_flag) { console.error('Error while resolving dir - already exist dir'); - errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR); + errorCallback && errorCallback(FileError.PATH_EXISTS_ERR); } else if (!create_flag && dir.isDirectory !== isDirectory) { console.error('Error while resolving dir - already exist file'); errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR); @@ -90,7 +101,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp } } else { console.error('Error - create flag is false - new directory would not be created'); - errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR); + errorCallback && errorCallback(FileError.NOT_FOUND_ERR); } }; -- 2.7.4