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

Side by Side Diff: lib/filterClasses.js

Issue 29760704: Issue 6592 - Implement $rewrite filter option (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created April 24, 2018, 8:31 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 | « no previous file | no next file » | 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-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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 text = text.substr(2); 764 text = text.substr(2);
765 } 765 }
766 766
767 let contentType = null; 767 let contentType = null;
768 let matchCase = null; 768 let matchCase = null;
769 let domains = null; 769 let domains = null;
770 let sitekeys = null; 770 let sitekeys = null;
771 let thirdParty = null; 771 let thirdParty = null;
772 let collapse = null; 772 let collapse = null;
773 let csp = null; 773 let csp = null;
774 let rewrite = null;
774 let options; 775 let options;
775 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); 776 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null);
776 if (match) 777 if (match)
777 { 778 {
778 options = match[1].split(","); 779 options = match[1].split(",");
779 text = match.input.substr(0, match.index); 780 text = match.input.substr(0, match.index);
780 for (let option of options) 781 for (let option of options)
781 { 782 {
782 let value = null; 783 let value = null;
783 let separatorIndex = option.indexOf("="); 784 let separatorIndex = option.indexOf("=");
(...skipping 27 matching lines...) Expand all
811 else if (option == "THIRD_PARTY") 812 else if (option == "THIRD_PARTY")
812 thirdParty = true; 813 thirdParty = true;
813 else if (option == "~THIRD_PARTY") 814 else if (option == "~THIRD_PARTY")
814 thirdParty = false; 815 thirdParty = false;
815 else if (option == "COLLAPSE") 816 else if (option == "COLLAPSE")
816 collapse = true; 817 collapse = true;
817 else if (option == "~COLLAPSE") 818 else if (option == "~COLLAPSE")
818 collapse = false; 819 collapse = false;
819 else if (option == "SITEKEY" && value) 820 else if (option == "SITEKEY" && value)
820 sitekeys = value.toUpperCase(); 821 sitekeys = value.toUpperCase();
822 else if (option == "REWRITE" && value)
823 rewrite = value;
821 else 824 else
822 return new InvalidFilter(origText, "filter_unknown_option"); 825 return new InvalidFilter(origText, "filter_unknown_option");
823 } 826 }
824 } 827 }
825 828
826 try 829 try
827 { 830 {
828 if (blocking) 831 if (blocking)
829 { 832 {
830 if (csp && Filter.invalidCSPRegExp.test(csp)) 833 if (csp && Filter.invalidCSPRegExp.test(csp))
831 return new InvalidFilter(origText, "filter_invalid_csp"); 834 return new InvalidFilter(origText, "filter_invalid_csp");
832 835
833 return new BlockingFilter(origText, text, contentType, matchCase, domains, 836 return new BlockingFilter(origText, text, contentType, matchCase, domains,
834 thirdParty, sitekeys, collapse, csp); 837 thirdParty, sitekeys, collapse, csp, rewrite);
835 } 838 }
836 return new WhitelistFilter(origText, text, contentType, matchCase, domains, 839 return new WhitelistFilter(origText, text, contentType, matchCase, domains,
837 thirdParty, sitekeys); 840 thirdParty, sitekeys);
838 } 841 }
839 catch (e) 842 catch (e)
840 { 843 {
841 return new InvalidFilter(origText, "filter_invalid_regexp"); 844 return new InvalidFilter(origText, "filter_invalid_regexp");
842 } 845 }
843 }; 846 };
844 847
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 * @param {string} regexpSource see RegExpFilter() 890 * @param {string} regexpSource see RegExpFilter()
888 * @param {number} contentType see RegExpFilter() 891 * @param {number} contentType see RegExpFilter()
889 * @param {boolean} matchCase see RegExpFilter() 892 * @param {boolean} matchCase see RegExpFilter()
890 * @param {string} domains see RegExpFilter() 893 * @param {string} domains see RegExpFilter()
891 * @param {boolean} thirdParty see RegExpFilter() 894 * @param {boolean} thirdParty see RegExpFilter()
892 * @param {string} sitekeys see RegExpFilter() 895 * @param {string} sitekeys see RegExpFilter()
893 * @param {boolean} collapse 896 * @param {boolean} collapse
894 * defines whether the filter should collapse blocked content, can be null 897 * defines whether the filter should collapse blocked content, can be null
895 * @param {string} [csp] 898 * @param {string} [csp]
896 * Content Security Policy to inject when the filter matches 899 * Content Security Policy to inject when the filter matches
900 * @param {string} [rewrite]
901 * The rewrite expression
897 * @constructor 902 * @constructor
898 * @augments RegExpFilter 903 * @augments RegExpFilter
899 */ 904 */
900 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, 905 function BlockingFilter(text, regexpSource, contentType, matchCase, domains,
901 thirdParty, sitekeys, collapse, csp) 906 thirdParty, sitekeys, collapse, csp, rewrite)
902 { 907 {
903 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, 908 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
904 thirdParty, sitekeys); 909 thirdParty, sitekeys);
905 910
906 this.collapse = collapse; 911 this.collapse = collapse;
907 this.csp = csp; 912 this.csp = csp;
913 this.rewrite = rewrite;
908 } 914 }
909 exports.BlockingFilter = BlockingFilter; 915 exports.BlockingFilter = BlockingFilter;
910 916
911 BlockingFilter.prototype = extend(RegExpFilter, { 917 BlockingFilter.prototype = extend(RegExpFilter, {
912 type: "blocking", 918 type: "blocking",
913 919
914 /** 920 /**
915 * Defines whether the filter should collapse blocked content. 921 * Defines whether the filter should collapse blocked content.
916 * Can be null (use the global preference). 922 * Can be null (use the global preference).
917 * @type {boolean} 923 * @type {boolean}
918 */ 924 */
919 collapse: null, 925 collapse: null,
920 926
921 /** 927 /**
922 * Content Security Policy to inject for matching requests. 928 * Content Security Policy to inject for matching requests.
923 * @type {string} 929 * @type {string}
924 */ 930 */
925 csp: null 931 csp: null,
932
933 /**
934 * The rewrite expression
935 * @type {string}
936 */
937 rewrite: null
926 }); 938 });
927 939
928 /** 940 /**
929 * Class for whitelist filters 941 * Class for whitelist filters
930 * @param {string} text see Filter() 942 * @param {string} text see Filter()
931 * @param {string} regexpSource see RegExpFilter() 943 * @param {string} regexpSource see RegExpFilter()
932 * @param {number} contentType see RegExpFilter() 944 * @param {number} contentType see RegExpFilter()
933 * @param {boolean} matchCase see RegExpFilter() 945 * @param {boolean} matchCase see RegExpFilter()
934 * @param {string} domains see RegExpFilter() 946 * @param {string} domains see RegExpFilter()
935 * @param {boolean} thirdParty see RegExpFilter() 947 * @param {boolean} thirdParty see RegExpFilter()
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 */ 1092 */
1081 function ElemHideEmulationFilter(text, domains, selector) 1093 function ElemHideEmulationFilter(text, domains, selector)
1082 { 1094 {
1083 ElemHideBase.call(this, text, domains, selector); 1095 ElemHideBase.call(this, text, domains, selector);
1084 } 1096 }
1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1097 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1086 1098
1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1099 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1088 type: "elemhideemulation" 1100 type: "elemhideemulation"
1089 }); 1101 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld