From 4ca8d3dd928a4c969e55d378f6f190a5e5f57d54 Mon Sep 17 00:00:00 2001 From: SungHyun Min Date: Fri, 23 Oct 2015 10:32:09 +0900 Subject: [PATCH] [FileSystem] Remove code for cutting last '/' Change-Id: I43e404dea387026d9cfee2df7d56d78765baaeee Signed-off-by: Sunghyun Min --- src/filesystem/js/common.js | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js index 3d56e38..fb450eb 100644 --- a/src/filesystem/js/common.js +++ b/src/filesystem/js/common.js @@ -112,20 +112,15 @@ var commonFS_ = (function() { } function mergeMultipleSlashes(str) { - var s = str[0]; - var resStr = s; - for (var i=1; i < str.length; ++i ) { - if (!(str[i] === s && str[i] === '/')) { - s = str[i]; - resStr+=str[i]; - } - } - return resStr; + var retStr = str.replace(/(^(file\:\/\/\/)|^(file\:\/\/)|\/)\/{0,}/g, '$1'); + return retStr; } function toRealPath(aPath) { var _fileRealPath = ''; + aPath = mergeMultipleSlashes(aPath); + if (aPath.indexOf(uriPrefix) === 0) { _fileRealPath = aPath.substr(uriPrefix.length); } else if (aPath[0] !== '/') { @@ -156,19 +151,14 @@ var commonFS_ = (function() { } else { _fileRealPath = aPath; } - // if path is valid try to cut last '/' if it is present - if (_fileRealPath) { - _fileRealPath = mergeMultipleSlashes(_fileRealPath); - var lastCharIndex = _fileRealPath.length-1; - if (_fileRealPath[lastCharIndex] === '/') { - _fileRealPath = _fileRealPath.substr(0,lastCharIndex); - } - } + return _fileRealPath; } function toVirtualPath(aPath) { + aPath = mergeMultipleSlashes(aPath); var _virtualPath = aPath; + if (_virtualPath.indexOf(uriPrefix) === 0) { _virtualPath = _virtualPath.substr(uriPrefix.length); } @@ -177,17 +167,12 @@ var commonFS_ = (function() { for (var virtual_root in cacheVirtualToReal) { var real_root_path = cacheVirtualToReal[virtual_root].path; - if (aPath.indexOf(real_root_path, 0) === 0) { - return aPath.replace(real_root_path, virtual_root); + if (_virtualPath.indexOf(real_root_path, 0) === 0) { + return _virtualPath.replace(real_root_path, virtual_root); } } - // cutting of last '/' if it is present - var lastCharIndex = aPath.length-1; - if (aPath[lastCharIndex] === '/') { - aPath = aPath.substr(0,lastCharIndex); - } - return mergeMultipleSlashes(aPath); + return _virtualPath; } function getFileInfo(aStatObj, secondIter, aMode) { -- 2.7.4