Index: lib/common.js |
=================================================================== |
--- a/lib/common.js |
+++ b/lib/common.js |
@@ -27,42 +27,51 @@ |
return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); |
} |
exports.textToRegExp = textToRegExp; |
/** |
* Converts filter text into regular expression string |
* @param {string} text as in Filter() |
+ * @param {boolean} [optimize=true] whether to optimize the regular expression |
* @return {string} regular expression representation of filter text |
*/ |
-function filterToRegExp(text) |
+function filterToRegExp(text, optimize = true) |
hub
2018/08/29 16:23:50
also, on second thought, I'm not certain that `opt
Manish Jethani
2018/09/01 14:57:52
OK, it already captures everything else, just not
|
{ |
+ if (optimize) |
+ { |
+ // remove multiple wildcards |
+ text = text.replace(/\*+/g, "*"); |
hub
2018/08/28 22:02:55
I think we should keep this one unconditionally li
Manish Jethani
2018/08/29 13:25:24
Since the `optimize` argument is supposed to skip
hub
2018/08/29 16:23:50
this is more about correctness IMHO. There is an e
Manish Jethani
2018/09/01 14:57:52
Alright, if we go with the renaming then it makes
|
+ |
+ // remove leading wildcard |
+ if (text[0] == "*") |
+ text = text.substring(1); |
+ |
+ // remove trailing wildcard |
+ if (text[text.length - 1] == "*") |
+ text = text.substring(0, text.length - 1); |
+ } |
+ |
return text |
- // remove multiple wildcards |
- .replace(/\*+/g, "*") |
// remove anchors following separator placeholder |
.replace(/\^\|$/, "^") |
// escape special symbols |
.replace(/\W/g, "\\$&") |
// replace wildcards by .* |
.replace(/\\\*/g, ".*") |
// process separator placeholders (all ANSI characters but alphanumeric |
// characters and _%.-) |
.replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F]|$)") |
// process extended anchor at expression start |
.replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") |
// process anchor at expression start |
.replace(/^\\\|/, "^") |
// process anchor at expression end |
- .replace(/\\\|$/, "$") |
- // remove leading wildcards |
- .replace(/^(\.\*)/, "") |
- // remove trailing wildcards |
- .replace(/(\.\*)$/, ""); |
+ .replace(/\\\|$/, "$"); |
} |
exports.filterToRegExp = filterToRegExp; |
function splitSelector(selector) |
{ |
if (!selector.includes(",")) |
return [selector]; |