| 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-2015 Eyeo GmbH | 3  * Copyright (C) 2006-2015 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 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); | 18 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); | 
| 19 | 19 | 
|  | 20 /** | 
|  | 21  * Parses and validates a filter given by the user. | 
|  | 22  * | 
|  | 23  * @param {string}  text | 
|  | 24  * @param {Boolean} [ignore_headers=false]  If true, no exception is raised | 
|  | 25  *                                          for filter list headers, instead | 
|  | 26  *                                          the function will return null. | 
|  | 27  * @return {Filter} | 
|  | 28  * @throws Will throw an exception if filter cannot be | 
|  | 29  *         parsed or contains an invalid CSS selector. | 
|  | 30  */ | 
| 20 function parseFilter(text, ignore_headers) | 31 function parseFilter(text, ignore_headers) | 
| 21 { | 32 { | 
| 22   text = Filter.normalize(text); | 33   text = Filter.normalize(text); | 
| 23   if (!text) | 34   if (!text) | 
| 24     return null; | 35     return null; | 
| 25 | 36 | 
| 26   if (text[0] == "[") | 37   if (text[0] == "[") | 
| 27   { | 38   { | 
| 28     if (ignore_headers) | 39     if (ignore_headers) | 
| 29       return null; | 40       return null; | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 51     catch (error) | 62     catch (error) | 
| 52     { | 63     { | 
| 53       throw ext.i18n.getMessage("invalid_css_selector", "'" + filter.selector + 
     "'"); | 64       throw ext.i18n.getMessage("invalid_css_selector", "'" + filter.selector + 
     "'"); | 
| 54     } | 65     } | 
| 55   } | 66   } | 
| 56 | 67 | 
| 57   return filter; | 68   return filter; | 
| 58 } | 69 } | 
| 59 exports.parseFilter = parseFilter; | 70 exports.parseFilter = parseFilter; | 
| 60 | 71 | 
|  | 72 /** | 
|  | 73  * Parses and validates a newline-separated list of filters given by the user. | 
|  | 74  * | 
|  | 75  * @param {string}  text | 
|  | 76  * @param {Boolean} [ignore_headers=false]  If true, filter list headers | 
|  | 77  *                                          will be stripped instead of | 
|  | 78  *                                          raising an exception. | 
|  | 79  * @return {Filter[]} | 
|  | 80  * @throws Will throw an exception if one of the filters cannot | 
|  | 81            be parsed or contains an invalid CSS selector. | 
|  | 82  */ | 
| 61 function parseFilters(text, ignore_headers) | 83 function parseFilters(text, ignore_headers) | 
| 62 { | 84 { | 
| 63   let lines = text.split("\n"); | 85   let lines = text.split("\n"); | 
| 64   let filters = []; | 86   let filters = []; | 
| 65 | 87 | 
| 66   for (let i = 0; i < lines.length; i++) | 88   for (let i = 0; i < lines.length; i++) | 
| 67   { | 89   { | 
| 68     let filter; | 90     let filter; | 
| 69     try | 91     try | 
| 70     { | 92     { | 
| 71       filter = parseFilter(lines[i], ignore_headers); | 93       filter = parseFilter(lines[i], ignore_headers); | 
| 72     } | 94     } | 
| 73     catch (error) | 95     catch (error) | 
| 74     { | 96     { | 
| 75       throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; | 97       throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; | 
| 76     } | 98     } | 
| 77 | 99 | 
| 78     if (filter) | 100     if (filter) | 
| 79       filters.push(filter); | 101       filters.push(filter); | 
| 80   } | 102   } | 
| 81 | 103 | 
| 82   return filters; | 104   return filters; | 
| 83 } | 105 } | 
| 84 exports.parseFilters = parseFilters; | 106 exports.parseFilters = parseFilters; | 
| OLD | NEW | 
|---|