| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 text = text.replace(/[^\S ]+/g, ""); | 181 text = text.replace(/[^\S ]+/g, ""); |
| 182 | 182 |
| 183 // Don't remove spaces inside comments | 183 // Don't remove spaces inside comments |
| 184 if (/^ *!/.test(text)) | 184 if (/^ *!/.test(text)) |
| 185 return text.trim(); | 185 return text.trim(); |
| 186 | 186 |
| 187 // Special treatment for element hiding filters, right side is allowed to | 187 // Special treatment for element hiding filters, right side is allowed to |
| 188 // contain spaces | 188 // contain spaces |
| 189 if (Filter.elemhideRegExp.test(text)) | 189 if (Filter.elemhideRegExp.test(text)) |
| 190 { | 190 { |
| 191 let [, domain, separator, selector] = /^(.*?)(#@?#?)(.*)$/.exec(text); | 191 let [, domains, separator, selector] = /^(.*?)(#@?#?)(.*)$/.exec(text); |
| 192 return domain.replace(/ +/g, "") + separator + selector.trim(); | 192 return domains.replace(/ +/g, "") + separator + selector.trim(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // For most regexp filters we strip all spaces, but $csp filter options | 195 // For most regexp filters we strip all spaces, but $csp filter options |
| 196 // are allowed to contain single (non trailing) spaces. | 196 // are allowed to contain single (non trailing) spaces. |
| 197 let strippedText = text.replace(/ +/g, ""); | 197 let strippedText = text.replace(/ +/g, ""); |
| 198 if (!strippedText.includes("$") || !/\bcsp=/i.test(strippedText)) | 198 if (!strippedText.includes("$") || !/\bcsp=/i.test(strippedText)) |
| 199 return strippedText; | 199 return strippedText; |
| 200 | 200 |
| 201 let optionsMatch = Filter.optionsRegExp.exec(strippedText); | 201 let optionsMatch = Filter.optionsRegExp.exec(strippedText); |
| 202 if (!optionsMatch) | 202 if (!optionsMatch) |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 * hidden | 958 * hidden |
| 959 * @constructor | 959 * @constructor |
| 960 * @augments ActiveFilter | 960 * @augments ActiveFilter |
| 961 */ | 961 */ |
| 962 function ElemHideBase(text, domains, selector) | 962 function ElemHideBase(text, domains, selector) |
| 963 { | 963 { |
| 964 ActiveFilter.call(this, text, domains || null); | 964 ActiveFilter.call(this, text, domains || null); |
| 965 | 965 |
| 966 if (domains) | 966 if (domains) |
| 967 { | 967 { |
| 968 this.selectorDomain = domains.replace(/,~[^,]+/g, "") | 968 this.selectorDomains = domains.replace(/,~[^,]+/g, "") |
| 969 .replace(/^~[^,]+,?/, "").toLowerCase(); | 969 .replace(/^~[^,]+,?/, "").toLowerCase(); |
| 970 } | 970 } |
| 971 | 971 |
| 972 // Braces are being escaped to prevent CSS rule injection. | 972 // Braces are being escaped to prevent CSS rule injection. |
| 973 this.selector = selector.replace("{", "\\7B ").replace("}", "\\7D "); | 973 this.selector = selector.replace("{", "\\7B ").replace("}", "\\7D "); |
| 974 } | 974 } |
| 975 exports.ElemHideBase = ElemHideBase; | 975 exports.ElemHideBase = ElemHideBase; |
| 976 | 976 |
| 977 ElemHideBase.prototype = extend(ActiveFilter, { | 977 ElemHideBase.prototype = extend(ActiveFilter, { |
| 978 /** | 978 /** |
| 979 * @see ActiveFilter.domainSeparator | 979 * @see ActiveFilter.domainSeparator |
| 980 */ | 980 */ |
| 981 domainSeparator: ",", | 981 domainSeparator: ",", |
| 982 | 982 |
| 983 /** | 983 /** |
| 984 * @see ActiveFilter.ignoreTrailingDot | 984 * @see ActiveFilter.ignoreTrailingDot |
| 985 */ | 985 */ |
| 986 ignoreTrailingDot: false, | 986 ignoreTrailingDot: false, |
| 987 | 987 |
| 988 /** | 988 /** |
| 989 * Host name or domain the filter should be restricted to (can be null for | 989 * Host names or domains the filter should be restricted to (can be null for |
| 990 * no restriction) | 990 * no restriction) |
| 991 * @type {string} | 991 * @type {string} |
| 992 */ | 992 */ |
| 993 selectorDomain: null, | 993 selectorDomains: null, |
| 994 /** | 994 /** |
| 995 * CSS selector for the HTML elements that should be hidden | 995 * CSS selector for the HTML elements that should be hidden |
| 996 * @type {string} | 996 * @type {string} |
| 997 */ | 997 */ |
| 998 selector: null | 998 selector: null |
| 999 }); | 999 }); |
| 1000 | 1000 |
| 1001 /** | 1001 /** |
| 1002 * Creates an element hiding filter from a pre-parsed text representation | 1002 * Creates an element hiding filter from a pre-parsed text representation |
| 1003 * | 1003 * |
| 1004 * @param {string} text same as in Filter() | 1004 * @param {string} text same as in Filter() |
| 1005 * @param {string?} domain | 1005 * @param {string?} domains |
| 1006 * domain part of the text representation | 1006 * domains part of the text representation |
| 1007 * @param {string?} type | 1007 * @param {string?} type |
| 1008 * rule type, either empty or @ (exception) or ? (emulation rule) | 1008 * rule type, either empty or @ (exception) or ? (emulation rule) |
| 1009 * @param {string} selector raw CSS selector | 1009 * @param {string} selector raw CSS selector |
| 1010 * @return {ElemHideFilter|ElemHideException| | 1010 * @return {ElemHideFilter|ElemHideException| |
| 1011 * ElemHideEmulationFilter|InvalidFilter} | 1011 * ElemHideEmulationFilter|InvalidFilter} |
| 1012 */ | 1012 */ |
| 1013 ElemHideBase.fromText = function(text, domain, type, selector) | 1013 ElemHideBase.fromText = function(text, domains, type, selector) |
| 1014 { | 1014 { |
| 1015 // We don't allow ElemHide filters which have any empty domains. | 1015 // We don't allow ElemHide filters which have any empty domains. |
| 1016 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that | 1016 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that |
| 1017 // changes this must be changed too. | 1017 // changes this must be changed too. |
| 1018 if (domain && /(^|,)~?(,|$)/.test(domain)) | 1018 if (domains && /(^|,)~?(,|$)/.test(domains)) |
| 1019 return new InvalidFilter(text, "filter_invalid_domain"); | 1019 return new InvalidFilter(text, "filter_invalid_domain"); |
| 1020 | 1020 |
| 1021 if (type == "@") | 1021 if (type == "@") |
| 1022 return new ElemHideException(text, domain, selector); | 1022 return new ElemHideException(text, domains, selector); |
| 1023 | 1023 |
| 1024 if (type == "?") | 1024 if (type == "?") |
| 1025 { | 1025 { |
| 1026 // Element hiding emulation filters are inefficient so we need to make sure | 1026 // Element hiding emulation filters are inefficient so we need to make sure |
| 1027 // that they're only applied if they specify active domains | 1027 // that they're only applied if they specify active domains |
| 1028 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) | 1028 if (!/,[^~][^,.]*\.[^,]/.test("," + domains)) |
| 1029 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); | 1029 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); |
| 1030 | 1030 |
| 1031 return new ElemHideEmulationFilter(text, domain, selector); | 1031 return new ElemHideEmulationFilter(text, domains, selector); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 return new ElemHideFilter(text, domain, selector); | 1034 return new ElemHideFilter(text, domains, selector); |
| 1035 }; | 1035 }; |
| 1036 | 1036 |
| 1037 /** | 1037 /** |
| 1038 * Class for element hiding filters | 1038 * Class for element hiding filters |
| 1039 * @param {string} text see Filter() | 1039 * @param {string} text see Filter() |
| 1040 * @param {string} domains see ElemHideBase() | 1040 * @param {string} domains see ElemHideBase() |
| 1041 * @param {string} selector see ElemHideBase() | 1041 * @param {string} selector see ElemHideBase() |
| 1042 * @constructor | 1042 * @constructor |
| 1043 * @augments ElemHideBase | 1043 * @augments ElemHideBase |
| 1044 */ | 1044 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 */ | 1080 */ |
| 1081 function ElemHideEmulationFilter(text, domains, selector) | 1081 function ElemHideEmulationFilter(text, domains, selector) |
| 1082 { | 1082 { |
| 1083 ElemHideBase.call(this, text, domains, selector); | 1083 ElemHideBase.call(this, text, domains, selector); |
| 1084 } | 1084 } |
| 1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
| 1086 | 1086 |
| 1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
| 1088 type: "elemhideemulation" | 1088 type: "elemhideemulation" |
| 1089 }); | 1089 }); |
| OLD | NEW |