[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 <p.kosko@samsung.com>
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('%');
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 + '.*';
}
}