| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-present eyeo GmbH | 3  * Copyright (C) 2006-present eyeo GmbH | 
| 4  * | 4  * | 
| 5  * Adblock Plus is free software: you can redistribute it and/or modify | 5  * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6  * it under the terms of the GNU General Public License version 3 as | 6  * it under the terms of the GNU General Public License version 3 as | 
| 7  * published by the Free Software Foundation. | 7  * published by the Free Software Foundation. | 
| 8  * | 8  * | 
| 9  * Adblock Plus is distributed in the hope that it will be useful, | 9  * Adblock Plus is distributed in the hope that it will be useful, | 
| 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 25 function textToRegExp(text) | 25 function textToRegExp(text) | 
| 26 { | 26 { | 
| 27   return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); | 27   return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); | 
| 28 } | 28 } | 
| 29 | 29 | 
| 30 exports.textToRegExp = textToRegExp; | 30 exports.textToRegExp = textToRegExp; | 
| 31 | 31 | 
| 32 /** | 32 /** | 
| 33  * Converts filter text into regular expression string | 33  * Converts filter text into regular expression string | 
| 34  * @param {string} text as in Filter() | 34  * @param {string} text as in Filter() | 
|  | 35  * @param {boolean} [captureAll=false] whether to enable the capturing of | 
|  | 36  *   leading and trailing wildcards in the filter text; by default, leading and | 
|  | 37  *   trailing wildcards are stripped out | 
| 35  * @return {string} regular expression representation of filter text | 38  * @return {string} regular expression representation of filter text | 
| 36  */ | 39  */ | 
| 37 function filterToRegExp(text) | 40 function filterToRegExp(text, captureAll = false) | 
| 38 { | 41 { | 
|  | 42   // remove multiple wildcards | 
|  | 43   text = text.replace(/\*+/g, "*"); | 
|  | 44 | 
|  | 45   if (!captureAll) | 
|  | 46   { | 
|  | 47     // remove leading wildcard | 
|  | 48     if (text[0] == "*") | 
|  | 49       text = text.substring(1); | 
|  | 50 | 
|  | 51     // remove trailing wildcard | 
|  | 52     if (text[text.length - 1] == "*") | 
|  | 53       text = text.substring(0, text.length - 1); | 
|  | 54   } | 
|  | 55 | 
| 39   return text | 56   return text | 
| 40     // remove multiple wildcards |  | 
| 41     .replace(/\*+/g, "*") |  | 
| 42     // remove anchors following separator placeholder | 57     // remove anchors following separator placeholder | 
| 43     .replace(/\^\|$/, "^") | 58     .replace(/\^\|$/, "^") | 
| 44     // escape special symbols | 59     // escape special symbols | 
| 45     .replace(/\W/g, "\\$&") | 60     .replace(/\W/g, "\\$&") | 
| 46     // replace wildcards by .* | 61     // replace wildcards by .* | 
| 47     .replace(/\\\*/g, ".*") | 62     .replace(/\\\*/g, ".*") | 
| 48     // process separator placeholders (all ANSI characters but alphanumeric | 63     // process separator placeholders (all ANSI characters but alphanumeric | 
| 49     // characters and _%.-) | 64     // characters and _%.-) | 
| 50     .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6
     0\\x7B-\\x7F]|$)") | 65     .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6
     0\\x7B-\\x7F]|$)") | 
| 51     // process extended anchor at expression start | 66     // process extended anchor at expression start | 
| 52     .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") | 67     .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") | 
| 53     // process anchor at expression start | 68     // process anchor at expression start | 
| 54     .replace(/^\\\|/, "^") | 69     .replace(/^\\\|/, "^") | 
| 55     // process anchor at expression end | 70     // process anchor at expression end | 
| 56     .replace(/\\\|$/, "$") | 71     .replace(/\\\|$/, "$"); | 
| 57     // remove leading wildcards |  | 
| 58     .replace(/^(\.\*)/, "") |  | 
| 59     // remove trailing wildcards |  | 
| 60     .replace(/(\.\*)$/, ""); |  | 
| 61 } | 72 } | 
| 62 | 73 | 
| 63 exports.filterToRegExp = filterToRegExp; | 74 exports.filterToRegExp = filterToRegExp; | 
| 64 | 75 | 
| 65 function splitSelector(selector) | 76 function splitSelector(selector) | 
| 66 { | 77 { | 
| 67   if (!selector.includes(",")) | 78   if (!selector.includes(",")) | 
| 68     return [selector]; | 79     return [selector]; | 
| 69 | 80 | 
| 70   let selectors = []; | 81   let selectors = []; | 
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 196     // Note that the first group in the regular expression is optional. If it | 207     // Note that the first group in the regular expression is optional. If it | 
| 197     // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. | 208     // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. | 
| 198     qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; | 209     qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; | 
| 199   } | 210   } | 
| 200 | 211 | 
| 201   // Remove the initial comma and space. | 212   // Remove the initial comma and space. | 
| 202   return qualifiedSelector.substr(2); | 213   return qualifiedSelector.substr(2); | 
| 203 } | 214 } | 
| 204 | 215 | 
| 205 exports.qualifySelector = qualifySelector; | 216 exports.qualifySelector = qualifySelector; | 
| OLD | NEW | 
|---|