Better globbing. Fix #12

This commit is contained in:
Thomas Lovén 2019-03-20 08:41:01 +01:00
parent be13234a43
commit e9571b6427

View File

@ -16,8 +16,11 @@ class AutoEntities extends cardTools.litElement() {
match(pattern, str){ match(pattern, str){
if (typeof(str) === "string" && typeof(pattern) === "string") { if (typeof(str) === "string" && typeof(pattern) === "string") {
if((pattern.startsWith('/') && pattern.endsWith('/')) || pattern.indexOf('*') !== -1) { if((pattern.startsWith('/') && pattern.endsWith('/')) || pattern.indexOf('*') !== -1) {
if(pattern[0] !== '/') if(pattern[0] !== '/') {
pattern = `/${pattern.replace(/\*/g, '.*')}/`; pattern = pattern.replace(/\./g, '\.');
pattern = pattern.replace(/\*/g, '.*');
pattern = `/^${pattern}$/`;
}
var regex = new RegExp(pattern.substr(1).slice(0,-1)); var regex = new RegExp(pattern.substr(1).slice(0,-1));
return regex.test(str); return regex.test(str);
} }