From 476a25e8a662270dfe5b37c560e4235f02b146e4 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 12:59:41 -0800 Subject: uri validation moved to file io apis Signed-off-by: Ananya Sen --- js/io/system/coreioapi.js | 21 +++++++++++++++++++++ .../new-file-options-navigator.js | 2 +- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 2 +- js/lib/NJUtils.js | 21 --------------------- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'js') diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index f4ab56b6..f0ca568f 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -983,6 +983,27 @@ exports.CoreIoApi = Montage.create(Component, { return retValue; } }, + + /*** + * checks for valid uri pattern + * also flags if Windows uri pattern and Unix uri patterns are mixed + */ + isValidUri:{ + value: function(uri){ + var isWindowsUri=false, isUnixUri=false,status=false; + if(uri !== ""){ + uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces + + //for local machine folder uri + isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); + isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix + status = isWindowsUri || isUnixUri; + if(isWindowsUri && isUnixUri){status = false;} + } + return status; + } + }, + //////////////////////////////////////////////////////////////////// /*** * check if the file exists diff --git a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js index cee8d4b7..a747b8de 100644 --- a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js +++ b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js @@ -335,7 +335,7 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C isValidUri:{ value: function(uri){ - var status= nj.isValidUri(uri); + var status= this.application.ninja.coreIoApi.isValidUri(uri); if(uri !== ""){ if(!status){ this.showError("! Invalid directory."); diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.js b/js/io/ui/save-as-dialog.reel/save-as-dialog.js index 371aa9a7..b20bed87 100644 --- a/js/io/ui/save-as-dialog.reel/save-as-dialog.js +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.js @@ -152,7 +152,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { isValidUri:{ value: function(uri){ - var status= nj.isValidUri(uri); + var status= this.application.ninja.coreIoApi.isValidUri(uri); if(uri !== ""){ if(!status){ this.showError("! Invalid directory."); diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 960c832f..74039e64 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -211,27 +211,6 @@ exports.NJUtils = Object.create(Object.prototype, { return path.substr(path.lastIndexOf('/') + 1); } }, - - /*** - * checks for valid uri pattern - * also flags if Windows uri pattern and Unix uri patterns are mixed - */ - isValidUri:{ - value: function(uri){ - var isWindowsUri=false, isUnixUri=false,status=false; - if(uri !== ""){ - uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces - - //for local machine folder uri - isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); - isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix - status = isWindowsUri || isUnixUri; - if(isWindowsUri && isUnixUri){status = false;} - } - return status; - } - }, - /*** * file name validation */ -- cgit v1.2.3