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

Side by Side Diff: lib/filterClasses.js

Issue 29336430: Issue 3659 - Remove locale dependency from filter classes (Closed)
Patch Set: Added missing license header Created Feb. 16, 2016, 11:58 a.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 | « README.md ('k') | package.json » ('j') | test_wrapper.js » ('J')
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-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 {Utils} = require("utils");
24 23
25 /** 24 /**
26 * Abstract base class for filters 25 * Abstract base class for filters
27 * 26 *
28 * @param {String} text string representation of the filter 27 * @param {String} text string representation of the filter
29 * @constructor 28 * @constructor
30 */ 29 */
31 function Filter(text) 30 function Filter(text)
32 { 31 {
33 this.text = text; 32 this.text = text;
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 thirdParty = true; 729 thirdParty = true;
731 else if (option == "~THIRD_PARTY") 730 else if (option == "~THIRD_PARTY")
732 thirdParty = false; 731 thirdParty = false;
733 else if (option == "COLLAPSE") 732 else if (option == "COLLAPSE")
734 collapse = true; 733 collapse = true;
735 else if (option == "~COLLAPSE") 734 else if (option == "~COLLAPSE")
736 collapse = false; 735 collapse = false;
737 else if (option == "SITEKEY" && typeof value != "undefined") 736 else if (option == "SITEKEY" && typeof value != "undefined")
738 sitekeys = value; 737 sitekeys = value;
739 else 738 else
740 return new InvalidFilter(origText, "Unknown option " + option.toLowerCas e()); 739 return new InvalidFilter(origText, "filter_unknown_option");
741 } 740 }
742 } 741 }
743 742
744 try 743 try
745 { 744 {
746 if (blocking) 745 if (blocking)
747 return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse); 746 return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse);
748 else 747 else
749 return new WhitelistFilter(origText, text, contentType, matchCase, domains , thirdParty, sitekeys); 748 return new WhitelistFilter(origText, text, contentType, matchCase, domains , thirdParty, sitekeys);
750 } 749 }
751 catch (e) 750 catch (e)
752 { 751 {
753 return new InvalidFilter(origText, e); 752 return new InvalidFilter(origText, "filter_invalid_regexp");
754 } 753 }
755 }; 754 };
756 755
757 /** 756 /**
758 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks 757 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks
759 */ 758 */
760 RegExpFilter.typeMap = { 759 RegExpFilter.typeMap = {
761 OTHER: 1, 760 OTHER: 1,
762 SCRIPT: 2, 761 SCRIPT: 2,
763 IMAGE: 4, 762 IMAGE: 4,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 rule = rule.substr(1, rule.length - 2); 919 rule = rule.substr(1, rule.length - 2);
921 let separatorPos = rule.indexOf("="); 920 let separatorPos = rule.indexOf("=");
922 if (separatorPos > 0) 921 if (separatorPos > 0)
923 { 922 {
924 rule = rule.replace(/=/, '="') + '"'; 923 rule = rule.replace(/=/, '="') + '"';
925 additional += "[" + rule + "]"; 924 additional += "[" + rule + "]";
926 } 925 }
927 else 926 else
928 { 927 {
929 if (id) 928 if (id)
930 return new InvalidFilter(text, Utils.getString("filter_elemhide_dupl icate_id")); 929 return new InvalidFilter(text, "filter_elemhide_duplicate_id");
931 930
932 id = rule; 931 id = rule;
933 } 932 }
934 } 933 }
935 } 934 }
936 935
937 if (id) 936 if (id)
938 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; 937 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional;
939 else if (tagName || additional) 938 else if (tagName || additional)
940 selector = tagName + additional; 939 selector = tagName + additional;
941 else 940 else
942 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocriteria ")); 941 return new InvalidFilter(text, "filter_elemhide_nocriteria");
943 } 942 }
944 943
945 if (isException) 944 if (isException)
946 return new ElemHideException(text, domain, selector); 945 return new ElemHideException(text, domain, selector);
947 946
948 let match = Filter.csspropertyRegExp.exec(selector); 947 let match = Filter.csspropertyRegExp.exec(selector);
949 if (match) 948 if (match)
950 { 949 {
951 // CSS property filters are inefficient so we need to make sure that 950 // CSS property filters are inefficient so we need to make sure that
952 // they're only applied if they specify active domains 951 // they're only applied if they specify active domains
953 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) 952 if (!/,[^~][^,.]*\.[^,]/.test("," + domain))
954 return new InvalidFilter(text, Utils.getString("filter_cssproperty_nodomai n")); 953 return new InvalidFilter(text, "filter_cssproperty_nodomain");
955 954
956 return new CSSPropertyFilter(text, domain, selector, match[2], 955 return new CSSPropertyFilter(text, domain, selector, match[2],
957 selector.substr(0, match.index), 956 selector.substr(0, match.index),
958 selector.substr(match.index + match[0].length)); 957 selector.substr(match.index + match[0].length));
959 } 958 }
960 959
961 return new ElemHideFilter(text, domain, selector); 960 return new ElemHideFilter(text, domain, selector);
962 }; 961 };
963 962
964 /** 963 /**
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 // several times on Safari, due to WebKit bug 132872 1060 // several times on Safari, due to WebKit bug 132872
1062 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); 1061 let prop = Object.getOwnPropertyDescriptor(this, "regexpString");
1063 if (prop) 1062 if (prop)
1064 return prop.value; 1063 return prop.value;
1065 1064
1066 let regexp = Filter.toRegExp(this.regexpSource); 1065 let regexp = Filter.toRegExp(this.regexpSource);
1067 Object.defineProperty(this, "regexpString", {value: regexp}); 1066 Object.defineProperty(this, "regexpString", {value: regexp});
1068 return regexp; 1067 return regexp;
1069 } 1068 }
1070 }; 1069 };
OLDNEW
« no previous file with comments | « README.md ('k') | package.json » ('j') | test_wrapper.js » ('J')

Powered by Google App Engine
This is Rietveld