Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterValidation.js

Issue 6270582551216128: Noissue - Renamed ignore_headers argument to use camelcase (Closed)
Patch Set: Created March 3, 2015, 9:09 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 20 /**
21 * Parses and validates a filter given by the user. 21 * Parses and validates a filter given by the user.
22 * 22 *
23 * @param {string} text 23 * @param {string} text
24 * @param {Boolean} [ignore_headers=false] If true, no exception is raised 24 * @param {Boolean} [ignoreHeaders=false] If true, no exception is raised
25 * for filter list headers, instead 25 * for filter list headers, instead
26 * the function will return null. 26 * the function will return null.
27 * @return {Filter} 27 * @return {Filter}
28 * @throws Will throw an exception if filter cannot be 28 * @throws Will throw an exception if filter cannot be
29 * parsed or contains an invalid CSS selector. 29 * parsed or contains an invalid CSS selector.
30 */ 30 */
31 function parseFilter(text, ignore_headers) 31 function parseFilter(text, ignoreHeaders)
32 { 32 {
33 text = Filter.normalize(text); 33 text = Filter.normalize(text);
34 if (!text) 34 if (!text)
35 return null; 35 return null;
36 36
37 if (text[0] == "[") 37 if (text[0] == "[")
38 { 38 {
39 if (ignore_headers) 39 if (ignoreHeaders)
40 return null; 40 return null;
41 41
42 throw ext.i18n.getMessage("unexpected_filter_list_header"); 42 throw ext.i18n.getMessage("unexpected_filter_list_header");
43 } 43 }
44 44
45 let filter = Filter.fromText(text); 45 let filter = Filter.fromText(text);
46 46
47 if (filter instanceof InvalidFilter) 47 if (filter instanceof InvalidFilter)
48 throw filter.reason; 48 throw filter.reason;
49 49
(...skipping 16 matching lines...) Expand all
66 } 66 }
67 67
68 return filter; 68 return filter;
69 } 69 }
70 exports.parseFilter = parseFilter; 70 exports.parseFilter = parseFilter;
71 71
72 /** 72 /**
73 * Parses and validates a newline-separated list of filters given by the user. 73 * Parses and validates a newline-separated list of filters given by the user.
74 * 74 *
75 * @param {string} text 75 * @param {string} text
76 * @param {Boolean} [ignore_headers=false] If true, filter list headers 76 * @param {Boolean} [ignoreHeaders=false] If true, filter list headers
77 * will be stripped instead of 77 * will be stripped instead of
78 * raising an exception. 78 * raising an exception.
79 * @return {Filter[]} 79 * @return {Filter[]}
80 * @throws Will throw an exception if one of the filters cannot 80 * @throws Will throw an exception if one of the filters cannot
81 be parsed or contains an invalid CSS selector. 81 be parsed or contains an invalid CSS selector.
82 */ 82 */
83 function parseFilters(text, ignore_headers) 83 function parseFilters(text, ignoreHeaders)
84 { 84 {
85 let lines = text.split("\n"); 85 let lines = text.split("\n");
86 let filters = []; 86 let filters = [];
87 87
88 for (let i = 0; i < lines.length; i++) 88 for (let i = 0; i < lines.length; i++)
89 { 89 {
90 let filter; 90 let filter;
91 try 91 try
92 { 92 {
93 filter = parseFilter(lines[i], ignore_headers); 93 filter = parseFilter(lines[i], ignoreHeaders);
94 } 94 }
95 catch (error) 95 catch (error)
96 { 96 {
97 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; 97 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error;
98 } 98 }
99 99
100 if (filter) 100 if (filter)
101 filters.push(filter); 101 filters.push(filter);
102 } 102 }
103 103
104 return filters; 104 return filters;
105 } 105 }
106 exports.parseFilters = parseFilters; 106 exports.parseFilters = parseFilters;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld