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

Side by Side Diff: lib/filterClasses.js

Issue 29470687: Issue 5344 - Element hiding emulation exceptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 21, 2017, 6:50 p.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 | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 /** 80 /**
81 * Cache for known filters, maps string representation to filter objects. 81 * Cache for known filters, maps string representation to filter objects.
82 * @type {Object} 82 * @type {Object}
83 */ 83 */
84 Filter.knownFilters = Object.create(null); 84 Filter.knownFilters = Object.create(null);
85 85
86 /** 86 /**
87 * Regular expression that element hiding filters should match 87 * Regular expression that element hiding filters should match
88 * @type {RegExp} 88 * @type {RegExp}
89 */ 89 */
90 Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/; 90 Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?^])?#(.+)$/;
91 /** 91 /**
92 * Regular expression that RegExp filters specified as RegExps should match 92 * Regular expression that RegExp filters specified as RegExps should match
93 * @type {RegExp} 93 * @type {RegExp}
94 */ 94 */
95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/;
96 /** 96 /**
97 * Regular expression that options on a RegExp filter should match 97 * Regular expression that options on a RegExp filter should match
98 * @type {RegExp} 98 * @type {RegExp}
99 */ 99 */
100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/; 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/;
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 /** 941 /**
942 * Creates an element hiding filter from a pre-parsed text representation 942 * Creates an element hiding filter from a pre-parsed text representation
943 * 943 *
944 * @param {string} text same as in Filter() 944 * @param {string} text same as in Filter()
945 * @param {string?} domain 945 * @param {string?} domain
946 * domain part of the text representation 946 * domain part of the text representation
947 * @param {string?} type 947 * @param {string?} type
948 * rule type, either empty or @ (exception) or ? (emulation rule) 948 * rule type, either empty or @ (exception) or ? (emulation rule)
949 * @param {string} selector raw CSS selector 949 * @param {string} selector raw CSS selector
950 * @return {ElemHideFilter|ElemHideException| 950 * @return {ElemHideFilter|ElemHideException|
951 * ElemHideEmulationFilter|InvalidFilter} 951 * ElemHideEmulationFilter|ElemHideEmulationException|InvalidFilter}
952 */ 952 */
953 ElemHideBase.fromText = function(text, domain, type, selector) 953 ElemHideBase.fromText = function(text, domain, type, selector)
954 { 954 {
955 // We don't allow ElemHide filters which have any empty domains. 955 // We don't allow ElemHide filters which have any empty domains.
956 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that 956 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that
957 // changes this must be changed too. 957 // changes this must be changed too.
958 if (domain && /(^|,)~?(,|$)/.test(domain)) 958 if (domain && /(^|,)~?(,|$)/.test(domain))
959 return new InvalidFilter(text, "filter_invalid_domain"); 959 return new InvalidFilter(text, "filter_invalid_domain");
960 960
961 if (type == "@") 961 if (type == "@")
962 return new ElemHideException(text, domain, selector); 962 return new ElemHideException(text, domain, selector);
963 963
964 if (type == "?") 964 if ((type == "?") || (type == "^"))
965 { 965 {
966 // Element hiding emulation filters are inefficient so we need to make sure 966 // Element hiding emulation filters are inefficient so we need to make sure
967 // that they're only applied if they specify active domains 967 // that they're only applied if they specify active domains
968 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) 968 if (!/,[^~][^,.]*\.[^,]/.test("," + domain))
969 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); 969 return new InvalidFilter(text, "filter_elemhideemulation_nodomain");
970 970
971 if (type == "^")
972 return new ElemHideEmulationException(text, domain, selector);
973
971 return new ElemHideEmulationFilter(text, domain, selector); 974 return new ElemHideEmulationFilter(text, domain, selector);
972 } 975 }
973 976
974 return new ElemHideFilter(text, domain, selector); 977 return new ElemHideFilter(text, domain, selector);
975 }; 978 };
976 979
977 /** 980 /**
981 * Base class for element hiding exceptions
982 * @param {string} text see Filter()
983 * @param {string} domains see ElemHideBase()
984 * @param {string} selector see ElemHideBase()
985 * @constructor
986 * @augments ElemHideBase
987 */
988 function ElemHideExceptionBase(text, domains, selector)
989 {
990 ElemHideBase.call(this, text, domains, selector);
991 }
992 exports.ElemHideExceptionBase = ElemHideExceptionBase;
993
994 ElemHideExceptionBase.prototype = extend(ElemHideBase, {
995 });
996
997 /**
978 * Class for element hiding filters 998 * Class for element hiding filters
979 * @param {string} text see Filter() 999 * @param {string} text see Filter()
980 * @param {string} domains see ElemHideBase() 1000 * @param {string} domains see ElemHideBase()
981 * @param {string} selector see ElemHideBase() 1001 * @param {string} selector see ElemHideBase()
982 * @constructor 1002 * @constructor
983 * @augments ElemHideBase 1003 * @augments ElemHideBase
984 */ 1004 */
985 function ElemHideFilter(text, domains, selector) 1005 function ElemHideFilter(text, domains, selector)
986 { 1006 {
987 ElemHideBase.call(this, text, domains, selector); 1007 ElemHideBase.call(this, text, domains, selector);
988 } 1008 }
989 exports.ElemHideFilter = ElemHideFilter; 1009 exports.ElemHideFilter = ElemHideFilter;
990 1010
991 ElemHideFilter.prototype = extend(ElemHideBase, { 1011 ElemHideFilter.prototype = extend(ElemHideBase, {
992 type: "elemhide" 1012 type: "elemhide"
993 }); 1013 });
994 1014
995 /** 1015 /**
996 * Class for element hiding exceptions 1016 * Class for element hiding exceptions
997 * @param {string} text see Filter() 1017 * @param {string} text see Filter()
998 * @param {string} domains see ElemHideBase() 1018 * @param {string} domains see ElemHideBase()
999 * @param {string} selector see ElemHideBase() 1019 * @param {string} selector see ElemHideBase()
1000 * @constructor 1020 * @constructor
1001 * @augments ElemHideBase 1021 * @augments ElemHideExceptionBase
1002 */ 1022 */
1003 function ElemHideException(text, domains, selector) 1023 function ElemHideException(text, domains, selector)
1004 { 1024 {
1005 ElemHideBase.call(this, text, domains, selector); 1025 ElemHideExceptionBase.call(this, text, domains, selector);
1006 } 1026 }
1007 exports.ElemHideException = ElemHideException; 1027 exports.ElemHideException = ElemHideException;
1008 1028
1009 ElemHideException.prototype = extend(ElemHideBase, { 1029 ElemHideException.prototype = extend(ElemHideExceptionBase, {
1010 type: "elemhideexception" 1030 type: "elemhideexception"
1011 }); 1031 });
1012 1032
1013 /** 1033 /**
1014 * Class for element hiding emulation filters 1034 * Class for element hiding emulation filters
1015 * @param {string} text see Filter() 1035 * @param {string} text see Filter()
1016 * @param {string} domains see ElemHideBase() 1036 * @param {string} domains see ElemHideBase()
1017 * @param {string} selector see ElemHideBase() 1037 * @param {string} selector see ElemHideBase()
1018 * @constructor 1038 * @constructor
1019 * @augments ElemHideBase 1039 * @augments ElemHideBase
1020 */ 1040 */
1021 function ElemHideEmulationFilter(text, domains, selector) 1041 function ElemHideEmulationFilter(text, domains, selector)
1022 { 1042 {
1023 ElemHideBase.call(this, text, domains, selector); 1043 ElemHideBase.call(this, text, domains, selector);
1024 } 1044 }
1025 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1045 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1026 1046
1027 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1047 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1028 type: "elemhideemulation" 1048 type: "elemhideemulation"
1029 }); 1049 });
1050
1051 /**
1052 * Class for element hiding emulation exceptions
1053 * @param {string} text see Filter()
1054 * @param {string} domains see ElemHideBase()
1055 * @param {string} selector see ElemHideBase()
1056 * @constructor
1057 * @augments ElemHideExceptionBase
1058 */
1059 function ElemHideEmulationException(text, domains, selector)
1060 {
1061 ElemHideExceptionBase.call(this, text, domains, selector);
1062 }
1063 exports.ElemHideEmulationException = ElemHideEmulationException;
1064
1065 ElemHideEmulationException.prototype = extend(ElemHideExceptionBase, {
1066 type: "elemhideemulationexception"
1067 });
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld