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-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 |
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 /** | 18 /** |
19 * @fileOverview Definition of Filter class and its subclasses. | 19 * @fileOverview Definition of Filter class and its subclasses. |
20 */ | 20 */ |
21 | 21 |
22 let {FilterNotifier} = require("filterNotifier"); | 22 let {FilterNotifier} = require("filterNotifier"); |
23 let {extend} = require("coreUtils"); | 23 let {extend} = require("coreUtils"); |
24 | 24 |
25 // Helper function used to determine if a filter has any empty domains or not. | |
26 function emptyDomains(domains, separator) | |
27 { | |
28 let emptySoFar = true; | |
29 for (let i = 0; i < domains.length; i++) | |
30 { | |
31 switch (domains[i]) | |
32 { | |
33 case separator: | |
34 if (emptySoFar) | |
35 return true; | |
36 emptySoFar = true; | |
37 break; | |
38 case "~": | |
39 break; | |
40 default: | |
41 emptySoFar = false; | |
42 } | |
43 } | |
44 return emptySoFar; | |
45 } | |
46 | |
25 /** | 47 /** |
26 * Abstract base class for filters | 48 * Abstract base class for filters |
27 * | 49 * |
28 * @param {String} text string representation of the filter | 50 * @param {String} text string representation of the filter |
29 * @constructor | 51 * @constructor |
30 */ | 52 */ |
31 function Filter(text) | 53 function Filter(text) |
32 { | 54 { |
33 this.text = text; | 55 this.text = text; |
34 this.subscriptions = []; | 56 this.subscriptions = []; |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 } | 939 } |
918 | 940 |
919 if (id) | 941 if (id) |
920 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; | 942 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; |
921 else if (tagName || additional) | 943 else if (tagName || additional) |
922 selector = tagName + additional; | 944 selector = tagName + additional; |
923 else | 945 else |
924 return new InvalidFilter(text, "filter_elemhide_nocriteria"); | 946 return new InvalidFilter(text, "filter_elemhide_nocriteria"); |
925 } | 947 } |
926 | 948 |
949 if (domain && emptyDomains(domain, ElemHideBase.prototype.domainSeparator)) | |
Wladimir Palant
2016/10/06 08:06:14
Why have this function rather than /(^|,)~?(,|$)/.
kzar
2016/10/06 08:53:55
Done.
| |
950 return new InvalidFilter(text, "filter_empty_domain"); | |
Wladimir Palant
2016/10/06 08:06:14
filter_invalid_domain? We allow empty domains, but
kzar
2016/10/06 08:53:56
Done.
| |
951 | |
927 if (isException) | 952 if (isException) |
928 return new ElemHideException(text, domain, selector); | 953 return new ElemHideException(text, domain, selector); |
929 | 954 |
930 let match = Filter.csspropertyRegExp.exec(selector); | 955 let match = Filter.csspropertyRegExp.exec(selector); |
931 if (match) | 956 if (match) |
932 { | 957 { |
933 // CSS property filters are inefficient so we need to make sure that | 958 // CSS property filters are inefficient so we need to make sure that |
934 // they're only applied if they specify active domains | 959 // they're only applied if they specify active domains |
935 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) | 960 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
936 return new InvalidFilter(text, "filter_cssproperty_nodomain"); | 961 return new InvalidFilter(text, "filter_cssproperty_nodomain"); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 // several times on Safari, due to WebKit bug 132872 | 1059 // several times on Safari, due to WebKit bug 132872 |
1035 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); | 1060 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); |
1036 if (prop) | 1061 if (prop) |
1037 return prop.value; | 1062 return prop.value; |
1038 | 1063 |
1039 let regexp = Filter.toRegExp(this.regexpSource); | 1064 let regexp = Filter.toRegExp(this.regexpSource); |
1040 Object.defineProperty(this, "regexpString", {value: regexp}); | 1065 Object.defineProperty(this, "regexpString", {value: regexp}); |
1041 return regexp; | 1066 return regexp; |
1042 } | 1067 } |
1043 }); | 1068 }); |
OLD | NEW |