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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 * | 108 * |
109 */ | 109 */ |
110 | 110 |
111 let parseFilter = | 111 let parseFilter = |
112 /** | 112 /** |
113 * Parses and validates a filter given by the user. | 113 * Parses and validates a filter given by the user. |
114 * | 114 * |
115 * @param {string} text | 115 * @param {string} text |
116 * @return {ParsedFilter} | 116 * @return {ParsedFilter} |
117 */ | 117 */ |
118 exports.parseFilter = function(text) | 118 exports.parseFilter = text => |
119 { | 119 { |
120 let filter = null; | 120 let filter = null; |
121 text = Filter.normalize(text); | 121 text = Filter.normalize(text); |
122 | 122 |
123 if (text) | 123 if (text) |
124 { | 124 { |
125 if (text[0] == "[") | 125 if (text[0] == "[") |
126 return {error: new FilterParsingError("unexpected-filter-list-header")}; | 126 return {error: new FilterParsingError("unexpected-filter-list-header")}; |
127 | 127 |
128 filter = Filter.fromText(text); | 128 filter = Filter.fromText(text); |
(...skipping 13 matching lines...) Expand all Loading... |
142 * @property {Filter[]} filters The parsed result without invalid filters. | 142 * @property {Filter[]} filters The parsed result without invalid filters. |
143 * @property {FilterParsingError[]} errors See {@link module:filterValidation~F
ilterParsingError FilterParsingError} | 143 * @property {FilterParsingError[]} errors See {@link module:filterValidation~F
ilterParsingError FilterParsingError} |
144 */ | 144 */ |
145 | 145 |
146 /** | 146 /** |
147 * Parses and validates a newline-separated list of filters given by the user. | 147 * Parses and validates a newline-separated list of filters given by the user. |
148 * | 148 * |
149 * @param {string} text | 149 * @param {string} text |
150 * @return {ParsedFilters} | 150 * @return {ParsedFilters} |
151 */ | 151 */ |
152 exports.parseFilters = function(text) | 152 exports.parseFilters = text => |
153 { | 153 { |
154 let lines = text.split("\n"); | 154 let lines = text.split("\n"); |
155 let filters = []; | 155 let filters = []; |
156 let errors = []; | 156 let errors = []; |
157 | 157 |
158 for (let i = 0; i < lines.length; i++) | 158 for (let i = 0; i < lines.length; i++) |
159 { | 159 { |
160 let {filter, error} = parseFilter(lines[i]); | 160 let {filter, error} = parseFilter(lines[i]); |
161 | 161 |
162 if (filter) | 162 if (filter) |
163 filters.push(filter); | 163 filters.push(filter); |
164 | 164 |
165 if (error) | 165 if (error) |
166 { | 166 { |
167 error.lineno = i + 1; | 167 error.lineno = i + 1; |
168 errors.push(error); | 168 errors.push(error); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 return {filters: filters, errors: errors}; | 172 return {filters: filters, errors: errors}; |
173 }; | 173 }; |
OLD | NEW |