From: Piotr Kosko Date: Tue, 24 Apr 2018 10:40:19 +0000 (+0200) Subject: [Filesystem] Fixing file filter X-Git-Tag: submit/tizen/20180427.125243~2^2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F07%2F177007%2F2;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Fixing file filter [Bug] 1. FileFilter name was not matching '%' wildcard on the beginning of filename 2. wildcard escaping need to be done by using '\\%' not '\%' - proper comment added in code to ease future investigations. [Verification] Code compiles successfully. TCT passrate is 100%. Below code: var filter = "piotr\\%kosko%"; function onsuccess(files) { console.log("There are " + files.length + " in the selected folder"); for (var i =0; i < files.length; ++i) { console.log(files[i].name) } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { dir.listFiles(onsuccess, onerror, {name: filter}); }, function(e) { console.log("Error " + e.message);}, "r"); for filter "piotr\\%kosko%" filters file: piotr%koskoTest for filter "%kosko%" filter files: piotrkoskoTest piotrkosko piotrTestkoskoTest kosko piotr%koskoTest piotr%kosko Change-Id: If7e6c3c3ad97a3d01a800916ba73c5f7749ae0cb Signed-off-by: Piotr Kosko --- diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index 524d7b6a..d5d2d20d 100644 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -73,7 +73,7 @@ function stringToRegex(str) { if (str === '') { return new RegExp(_regString, 'i'); } - + // single '\' sign is not visible in JS string, escaping % wildcard need to be done by '\\%' str = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); var _percentTokens = str.split('%'); @@ -81,11 +81,13 @@ function stringToRegex(str) { for (i = 0; i < _percentTokens.length - 1; ++i) { _regString = _regString + _percentTokens[i]; if (_regString[_regString.length - 1] === '\\') { + // special handling \\% sequence - '%' sign is threaten as regular sign - not wildcard _regString = _regString.split(''); _regString.pop(); _regString = _regString.join('') + '%'; } - else if (_regString.lastIndexOf('\*') !== _regString.length - 2) { + else { + // handling '%' as a wildcard _regString = _regString + '.*'; } }