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

Delta Between Two Patch Sets: lib/filterValidation.js

Issue 5655474749833216: Issue 2658 - Got rid of try..catch for filter validation (Closed)
Left Patch Set: Created June 7, 2015, 2:47 p.m.
Right Patch Set: Improved comments Created June 8, 2015, 11:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | options.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 catch (e) 34 catch (e)
35 { 35 {
36 return false; 36 return false;
37 } 37 }
38 return true; 38 return true;
39 } 39 }
40 40
41 /** 41 /**
42 * @typedef ParsedFilter 42 * @typedef ParsedFilter
43 * @property {?Filter} [filter] The parsed filter is it is valid. Or null if 43 * @property {?Filter} [filter] The parsed filter if it is valid. Or null if
kzar 2015/06/08 11:28:04 Nit: Typo "The parsed filter_if_ it is valid"
Sebastian Noack 2015/06/08 12:00:08 Done.
44 * the given string is empty or a filter list head er. 44 * the given string is empty or a filter list head er.
45 * @property {string} [error] An error message indicated that the filter cann ot 45 * @property {string} [error] An error message indicated that the filter cann ot
46 * be parsed or contains an invalid CSS selector. 46 * be parsed or contains an invalid CSS selector.
47 */ 47 */
48 48
49 let parseFilter = 49 let parseFilter =
50 /** 50 /**
51 * Parses and validates a filter given by the user. 51 * Parses and validates a filter given by the user.
52 * 52 *
53 * @param {string} text 53 * @param {string} text
54 * @param {Boolean} [ignoreHeaders=false] If true, no error is produced 54 * @param {Boolean} [ignoreHeaders=false] If true, {filter: null} is
55 * for filter list headers, instead 55 returned instead an error
56 * {filter: null} is returned. 56 for filter list headers.
57 * @return {ParsedFilter} 57 * @return {ParsedFilter}
58 */ 58 */
59 exports.parseFilter = function(text, ignoreHeaders) 59 exports.parseFilter = function(text, ignoreHeaders)
60 { 60 {
61 let filter = null; 61 let filter = null;
62 text = Filter.normalize(text); 62 text = Filter.normalize(text);
63 63
64 if (text) 64 if (text)
65 { 65 {
66 if (text[0] != "[") 66 if (text[0] != "[")
(...skipping 21 matching lines...) Expand all
88 * @property {string} [error] An error message indicated that any filter ca nnot 88 * @property {string} [error] An error message indicated that any filter ca nnot
89 * be parsed or contains an invalid CSS selector . 89 * be parsed or contains an invalid CSS selector .
90 */ 90 */
91 91
92 /** 92 /**
93 * Parses and validates a newline-separated list of filters given by the user. 93 * Parses and validates a newline-separated list of filters given by the user.
94 * 94 *
95 * @param {string} text 95 * @param {string} text
96 * @param {Boolean} [ignoreHeaders=false] If true, filter list headers 96 * @param {Boolean} [ignoreHeaders=false] If true, filter list headers
97 * will be stripped instead of 97 * will be stripped instead of
98 * producing an error. 98 * returning an error.
kzar 2015/06/08 11:28:04 Nit: "returning"?
Sebastian Noack 2015/06/08 12:00:08 I did not say to "return" an error, because strict
99 * @return {ParsedFilters} 99 * @return {ParsedFilters}
100 */ 100 */
101 exports.parseFilters = function(text, ignoreHeaders) 101 exports.parseFilters = function(text, ignoreHeaders)
102 { 102 {
103 let lines = text.split("\n"); 103 let lines = text.split("\n");
104 let filters = []; 104 let filters = [];
105 105
106 for (let i = 0; i < lines.length; i++) 106 for (let i = 0; i < lines.length; i++)
107 { 107 {
108 let {filter, error} = parseFilter(lines[i], ignoreHeaders); 108 let {filter, error} = parseFilter(lines[i], ignoreHeaders);
109 109
110 if (error) 110 if (error)
111 return {error: ext.i18n.getMessage("line", (i + 1).toString()) + ": " + er ror}; 111 return {error: ext.i18n.getMessage("line", (i + 1).toString()) + ": " + er ror};
112 112
113 if (filter) 113 if (filter)
kzar 2015/06/08 11:28:04 Nit: Should be `else if (filter)` IMO
Sebastian Noack 2015/06/08 12:00:08 No, it shouldn't. The else would be redundant, as
114 filters.push(filter); 114 filters.push(filter);
115 } 115 }
116 116
117 return {filters: filters}; 117 return {filters: filters};
118 }; 118 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld