Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 | |
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 | 24 |
47 /** | 25 /** |
48 * Abstract base class for filters | 26 * Abstract base class for filters |
49 * | 27 * |
50 * @param {String} text string representation of the filter | 28 * @param {String} text string representation of the filter |
51 * @constructor | 29 * @constructor |
52 */ | 30 */ |
53 function Filter(text) | 31 function Filter(text) |
54 { | 32 { |
55 this.text = text; | 33 this.text = text; |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 } | 917 } |
940 | 918 |
941 if (id) | 919 if (id) |
942 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; | 920 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; |
943 else if (tagName || additional) | 921 else if (tagName || additional) |
944 selector = tagName + additional; | 922 selector = tagName + additional; |
945 else | 923 else |
946 return new InvalidFilter(text, "filter_elemhide_nocriteria"); | 924 return new InvalidFilter(text, "filter_elemhide_nocriteria"); |
947 } | 925 } |
948 | 926 |
949 if (domain && emptyDomains(domain, ElemHideBase.prototype.domainSeparator)) | 927 // We don't allow ElemHide filters which have any empty domains. |
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"); | 928 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that |
Wladimir Palant
2016/10/06 08:06:14
filter_invalid_domain? We allow empty domains, but
kzar
2016/10/06 08:53:56
Done.
| |
929 // changes this must be changed too. | |
930 if (domain && /(^|,)~?(,|$)/.test(domain)) | |
931 return new InvalidFilter(text, "filter_invalid_domain"); | |
951 | 932 |
952 if (isException) | 933 if (isException) |
953 return new ElemHideException(text, domain, selector); | 934 return new ElemHideException(text, domain, selector); |
954 | 935 |
955 let match = Filter.csspropertyRegExp.exec(selector); | 936 let match = Filter.csspropertyRegExp.exec(selector); |
956 if (match) | 937 if (match) |
957 { | 938 { |
958 // CSS property filters are inefficient so we need to make sure that | 939 // CSS property filters are inefficient so we need to make sure that |
959 // they're only applied if they specify active domains | 940 // they're only applied if they specify active domains |
960 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) | 941 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 // several times on Safari, due to WebKit bug 132872 | 1040 // several times on Safari, due to WebKit bug 132872 |
1060 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); | 1041 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); |
1061 if (prop) | 1042 if (prop) |
1062 return prop.value; | 1043 return prop.value; |
1063 | 1044 |
1064 let regexp = Filter.toRegExp(this.regexpSource); | 1045 let regexp = Filter.toRegExp(this.regexpSource); |
1065 Object.defineProperty(this, "regexpString", {value: regexp}); | 1046 Object.defineProperty(this, "regexpString", {value: regexp}); |
1066 return regexp; | 1047 return regexp; |
1067 } | 1048 } |
1068 }); | 1049 }); |
LEFT | RIGHT |