| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Converts raw text into a regular expression string | 21 * Converts raw text into a regular expression string |
| 22 * @param {string} text the string to convert | 22 * @param {string} text the string to convert |
| 23 * @return {string} regular expression representation of the text | 23 * @return {string} regular expression representation of the text |
| 24 */ | 24 */ |
| 25 function textToRegExp(text) | 25 export function textToRegExp(text) |
| 26 { | 26 { |
| 27 return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); | 27 return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); |
| 28 } | 28 } |
| 29 | 29 |
| 30 exports.textToRegExp = textToRegExp; | |
| 31 | |
| 32 /** | 30 /** |
| 33 * Converts filter text into regular expression string | 31 * Converts filter text into regular expression string |
| 34 * @param {string} text as in Filter() | 32 * @param {string} text as in Filter() |
| 35 * @return {string} regular expression representation of filter text | 33 * @return {string} regular expression representation of filter text |
| 36 */ | 34 */ |
| 37 function filterToRegExp(text) | 35 export function filterToRegExp(text) |
| 38 { | 36 { |
| 39 return text | 37 return text |
| 40 // remove multiple wildcards | 38 // remove multiple wildcards |
| 41 .replace(/\*+/g, "*") | 39 .replace(/\*+/g, "*") |
| 42 // remove anchors following separator placeholder | 40 // remove anchors following separator placeholder |
| 43 .replace(/\^\|$/, "^") | 41 .replace(/\^\|$/, "^") |
| 44 // escape special symbols | 42 // escape special symbols |
| 45 .replace(/\W/g, "\\$&") | 43 .replace(/\W/g, "\\$&") |
| 46 // replace wildcards by .* | 44 // replace wildcards by .* |
| 47 .replace(/\\\*/g, ".*") | 45 .replace(/\\\*/g, ".*") |
| 48 // process separator placeholders (all ANSI characters but alphanumeric | 46 // process separator placeholders (all ANSI characters but alphanumeric |
| 49 // characters and _%.-) | 47 // characters and _%.-) |
| 50 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6
0\\x7B-\\x7F]|$)") | 48 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6
0\\x7B-\\x7F]|$)") |
| 51 // process extended anchor at expression start | 49 // process extended anchor at expression start |
| 52 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") | 50 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") |
| 53 // process anchor at expression start | 51 // process anchor at expression start |
| 54 .replace(/^\\\|/, "^") | 52 .replace(/^\\\|/, "^") |
| 55 // process anchor at expression end | 53 // process anchor at expression end |
| 56 .replace(/\\\|$/, "$") | 54 .replace(/\\\|$/, "$") |
| 57 // remove leading wildcards | 55 // remove leading wildcards |
| 58 .replace(/^(\.\*)/, "") | 56 .replace(/^(\.\*)/, "") |
| 59 // remove trailing wildcards | 57 // remove trailing wildcards |
| 60 .replace(/(\.\*)$/, ""); | 58 .replace(/(\.\*)$/, ""); |
| 61 } | 59 } |
| 62 | 60 |
| 63 exports.filterToRegExp = filterToRegExp; | 61 export function splitSelector(selector) |
| 64 | |
| 65 function splitSelector(selector) | |
| 66 { | 62 { |
| 67 if (selector.indexOf(",") == -1) | 63 if (selector.indexOf(",") == -1) |
| 68 return [selector]; | 64 return [selector]; |
| 69 | 65 |
| 70 let selectors = []; | 66 let selectors = []; |
| 71 let start = 0; | 67 let start = 0; |
| 72 let level = 0; | 68 let level = 0; |
| 73 let sep = ""; | 69 let sep = ""; |
| 74 | 70 |
| 75 for (let i = 0; i < selector.length; i++) | 71 for (let i = 0; i < selector.length; i++) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 92 { | 88 { |
| 93 selectors.push(selector.substring(start, i)); | 89 selectors.push(selector.substring(start, i)); |
| 94 start = i + 1; | 90 start = i + 1; |
| 95 } | 91 } |
| 96 } | 92 } |
| 97 } | 93 } |
| 98 | 94 |
| 99 selectors.push(selector.substring(start)); | 95 selectors.push(selector.substring(start)); |
| 100 return selectors; | 96 return selectors; |
| 101 } | 97 } |
| 102 | |
| 103 exports.splitSelector = splitSelector; | |
| OLD | NEW |