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: Rebase Created June 8, 2018, 4:12 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 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 text = match.input.substr(0, match.index); 748 text = match.input.substr(0, match.index);
749 for (let option of options) 749 for (let option of options)
750 { 750 {
751 let value = null; 751 let value = null;
752 let separatorIndex = option.indexOf("="); 752 let separatorIndex = option.indexOf("=");
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 let type = (option[0] == "~" ? option.substr(1) : option) 758
759 .replace(/-/, "_").toUpperCase(); 759 let inverse = option[0] == "~";
760 option = option.toLowerCase(); 760 if (inverse)
761 if (type in RegExpFilter.typeMap) 761 option = option.substr(1);
762
763 let type = RegExpFilter.typeMap[option.replace(/-/, "_").toUpperCase()];
764 if (type)
762 { 765 {
763 if (option[0] == "~") 766 if (inverse)
764 { 767 {
765 if (contentType == null) 768 if (contentType == null)
766 ({contentType} = RegExpFilter.prototype); 769 ({contentType} = RegExpFilter.prototype);
767 contentType &= ~RegExpFilter.typeMap[type]; 770 contentType &= ~type;
768 } 771 }
769 else 772 else
770 { 773 {
771 if (contentType == null) 774 contentType |= type;
772 contentType = 0; 775
773 contentType |= RegExpFilter.typeMap[type]; 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
774
775 if (type == "CSP" && value)
776 csp = value; 777 csp = value;
777 } 778 }
778 } 779 }
779 else if (option == "match-case")
780 matchCase = true;
781 else if (option == "~match-case")
782 matchCase = false;
783 else if (option == "domain" && value)
784 domains = value.toLowerCase();
785 else if (option == "third-party")
786 thirdParty = true;
787 else if (option == "~third-party")
788 thirdParty = false;
789 else if (option == "collapse")
790 collapse = true;
791 else if (option == "~collapse")
792 collapse = false;
793 else if (option == "sitekey" && value)
794 sitekeys = value.toUpperCase();
795 else if (option == "rewrite" && value)
796 rewrite = value;
797 else 780 else
798 return new InvalidFilter(origText, "filter_unknown_option"); 781 {
782 switch (option.toLowerCase())
783 {
784 case "match-case":
785 matchCase = !inverse;
786 break;
787 case "domain":
788 if (!value)
789 return new InvalidFilter(origText, "filter_unknown_option");
790 domains = value.toLowerCase();
791 break;
792 case "third-party":
793 thirdParty = !inverse;
794 break;
795 case "collapse":
796 collapse = !inverse;
797 break;
798 case "sitekey":
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.
800 return new InvalidFilter(origText, "filter_unknown_option");
801 sitekeys = value.toUpperCase();
802 break;
803 case "rewrite":
804 if (!value)
Manish Jethani 2018/06/08 14:19:42 Note that this will get updated for the rewrite op
805 return new InvalidFilter(origText, "filter_unknown_option");
806 rewrite = value;
807 break;
808 default:
809 return new InvalidFilter(origText, "filter_unknown_option");
810 }
811 }
799 } 812 }
800 } 813 }
801 814
802 // For security reasons, never match $rewrite filters 815 // For security reasons, never match $rewrite filters
803 // against requests that might load any code to be executed. 816 // against requests that might load any code to be executed.
804 if (rewrite != null) 817 if (rewrite != null)
805 { 818 {
806 if (contentType == null) 819 if (contentType == null)
807 ({contentType} = RegExpFilter.prototype); 820 ({contentType} = RegExpFilter.prototype);
808 contentType &= ~(RegExpFilter.typeMap.SCRIPT | 821 contentType &= ~(RegExpFilter.typeMap.SCRIPT |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 */ 1100 */
1088 function ElemHideEmulationFilter(text, domains, selector) 1101 function ElemHideEmulationFilter(text, domains, selector)
1089 { 1102 {
1090 ElemHideBase.call(this, text, domains, selector); 1103 ElemHideBase.call(this, text, domains, selector);
1091 } 1104 }
1092 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1105 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1093 1106
1094 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1107 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1095 type: "elemhideemulation" 1108 type: "elemhideemulation"
1096 }); 1109 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld