Left: | ||
Right: |
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 * but null is returned instead, | |
26 * if a filter list header is given. | |
Wladimir Palant
2015/03/02 20:45:15
I have a hard time parsing that sentence :)
How a
Sebastian Noack
2015/03/03 09:07:48
Done.
| |
27 * @return {Filter} | |
28 * @throws Will throw an error if filter cannot be parsed | |
Wladimir Palant
2015/03/02 20:45:15
Nit: "throw an exception"?
Sebastian Noack
2015/03/03 09:07:48
Done.
| |
29 * 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 | |
77 * headers are stripped. | |
Wladimir Palant
2015/03/02 20:45:15
"If true, filter list headers will be stripped ins
Sebastian Noack
2015/03/03 09:07:48
Done.
| |
78 * @return {Filter[]} | |
79 * @throws Will throw an error if one of the filters cannot | |
80 be parsed or contains an invalid CSS selector. | |
81 */ | |
61 function parseFilters(text, ignore_headers) | 82 function parseFilters(text, ignore_headers) |
62 { | 83 { |
63 let lines = text.split("\n"); | 84 let lines = text.split("\n"); |
64 let filters = []; | 85 let filters = []; |
65 | 86 |
66 for (let i = 0; i < lines.length; i++) | 87 for (let i = 0; i < lines.length; i++) |
67 { | 88 { |
68 let filter; | 89 let filter; |
69 try | 90 try |
70 { | 91 { |
71 filter = parseFilter(lines[i], ignore_headers); | 92 filter = parseFilter(lines[i], ignore_headers); |
72 } | 93 } |
73 catch (error) | 94 catch (error) |
74 { | 95 { |
75 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; | 96 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; |
76 } | 97 } |
77 | 98 |
78 if (filter) | 99 if (filter) |
79 filters.push(filter); | 100 filters.push(filter); |
80 } | 101 } |
81 | 102 |
82 return filters; | 103 return filters; |
83 } | 104 } |
84 exports.parseFilters = parseFilters; | 105 exports.parseFilters = parseFilters; |
OLD | NEW |