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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29800595: Issue 6735 - Store domains in lower case (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Use Map version of RegExpFilter.typeMap Created June 8, 2018, 5:27 a.m.
Right Patch Set: Disallow missing values in domain, sitekey, and rewrite Created June 8, 2018, 2:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 if (separatorIndex >= 0) 753 if (separatorIndex >= 0)
754 { 754 {
755 value = option.substr(separatorIndex + 1); 755 value = option.substr(separatorIndex + 1);
756 option = option.substr(0, separatorIndex); 756 option = option.substr(0, separatorIndex);
757 } 757 }
758 758
759 let inverse = option[0] == "~"; 759 let inverse = option[0] == "~";
760 if (inverse) 760 if (inverse)
761 option = option.substr(1); 761 option = option.substr(1);
762 762
763 option = option.toLowerCase(); 763 let type = RegExpFilter.typeMap[option.replace(/-/, "_").toUpperCase()];
764
765 let type = typeMap.get(option);
766 if (type) 764 if (type)
767 { 765 {
768 if (inverse) 766 if (inverse)
769 { 767 {
770 if (contentType == null) 768 if (contentType == null)
771 ({contentType} = RegExpFilter.prototype); 769 ({contentType} = RegExpFilter.prototype);
772 contentType &= ~type; 770 contentType &= ~type;
773 } 771 }
774 else 772 else
775 { 773 {
776 contentType |= type; 774 contentType |= type;
777 775
778 if (type == RegExpFilter.typeMap.CSP && value) 776 if (type == RegExpFilter.typeMap.CSP && value)
Manish Jethani 2018/06/08 14:21:14 By the way in the case of csp we quietly ignore th
kzar 2018/06/15 10:44:03 Yea, agreed. By the way Rosie is reimplementing th
779 csp = value; 777 csp = value;
780 } 778 }
781 } 779 }
782 else 780 else
783 { 781 {
784 switch (option) 782 switch (option.toLowerCase())
785 { 783 {
786 case "match-case": 784 case "match-case":
787 matchCase = !inverse; 785 matchCase = !inverse;
788 break; 786 break;
789 case "domain": 787 case "domain":
790 if (value) 788 if (!value)
791 domains = value.toLowerCase(); 789 return new InvalidFilter(origText, "filter_unknown_option");
790 domains = value.toLowerCase();
792 break; 791 break;
793 case "third-party": 792 case "third-party":
794 thirdParty = !inverse; 793 thirdParty = !inverse;
795 break; 794 break;
796 case "collapse": 795 case "collapse":
797 collapse = !inverse; 796 collapse = !inverse;
798 break; 797 break;
799 case "sitekey": 798 case "sitekey":
800 if (value) 799 if (!value)
Manish Jethani 2018/06/08 14:19:42 There's a bit of code repetition here but I'm OK w
kzar 2018/06/15 10:44:03 Yea, I think it's fine.
801 sitekeys = value.toUpperCase(); 800 return new InvalidFilter(origText, "filter_unknown_option");
801 sitekeys = value.toUpperCase();
802 break; 802 break;
803 case "rewrite": 803 case "rewrite":
804 if (value) 804 if (!value)
Manish Jethani 2018/06/08 14:19:42 Note that this will get updated for the rewrite op
805 rewrite = value; 805 return new InvalidFilter(origText, "filter_unknown_option");
806 rewrite = value;
806 break; 807 break;
807 default: 808 default:
808 return new InvalidFilter(origText, "filter_unknown_option"); 809 return new InvalidFilter(origText, "filter_unknown_option");
809 } 810 }
810 } 811 }
811 } 812 }
812 } 813 }
813 814
814 // For security reasons, never match $rewrite filters 815 // For security reasons, never match $rewrite filters
815 // against requests that might load any code to be executed. 816 // against requests that might load any code to be executed.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 FONT: 32768, 866 FONT: 32768,
866 867
867 BACKGROUND: 4, // Backwards compat, same as IMAGE 868 BACKGROUND: 4, // Backwards compat, same as IMAGE
868 869
869 POPUP: 0x10000000, 870 POPUP: 0x10000000,
870 GENERICBLOCK: 0x20000000, 871 GENERICBLOCK: 0x20000000,
871 ELEMHIDE: 0x40000000, 872 ELEMHIDE: 0x40000000,
872 GENERICHIDE: 0x80000000 873 GENERICHIDE: 0x80000000
873 }; 874 };
874 875
875 // Create a Map version of RegExpFilter.typeMap for faster lookups and fewer
876 // string transformations in RegExpFilter.fromText
877 let typeMap = new Map(
878 Object.keys(RegExpFilter.typeMap).map(
879 key => [key.replace("_", "-").toLowerCase(), RegExpFilter.typeMap[key]]
880 )
881 );
882
883 // CSP, DOCUMENT, ELEMHIDE, POPUP, GENERICHIDE and GENERICBLOCK options 876 // CSP, DOCUMENT, ELEMHIDE, POPUP, GENERICHIDE and GENERICBLOCK options
884 // shouldn't be there by default 877 // shouldn't be there by default
885 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.CSP | 878 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.CSP |
886 RegExpFilter.typeMap.DOCUMENT | 879 RegExpFilter.typeMap.DOCUMENT |
887 RegExpFilter.typeMap.ELEMHIDE | 880 RegExpFilter.typeMap.ELEMHIDE |
888 RegExpFilter.typeMap.POPUP | 881 RegExpFilter.typeMap.POPUP |
889 RegExpFilter.typeMap.GENERICHIDE | 882 RegExpFilter.typeMap.GENERICHIDE |
890 RegExpFilter.typeMap.GENERICBLOCK); 883 RegExpFilter.typeMap.GENERICBLOCK);
891 884
892 /** 885 /**
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 */ 1100 */
1108 function ElemHideEmulationFilter(text, domains, selector) 1101 function ElemHideEmulationFilter(text, domains, selector)
1109 { 1102 {
1110 ElemHideBase.call(this, text, domains, selector); 1103 ElemHideBase.call(this, text, domains, selector);
1111 } 1104 }
1112 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1105 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1113 1106
1114 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1107 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1115 type: "elemhideemulation" 1108 type: "elemhideemulation"
1116 }); 1109 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld