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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29760704: Issue 6592 - Implement $rewrite filter option (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Comment fixes. Created May 11, 2018, 3:57 p.m.
Right Patch Set: Just inject URL into the sandbox globals. Created May 17, 2018, 12:50 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 | « no previous file | test/.eslintrc.json » ('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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 * @param {string} regexpSource see RegExpFilter() 889 * @param {string} regexpSource see RegExpFilter()
890 * @param {number} [contentType] see RegExpFilter() 890 * @param {number} [contentType] see RegExpFilter()
891 * @param {boolean} [matchCase] see RegExpFilter() 891 * @param {boolean} [matchCase] see RegExpFilter()
892 * @param {string} [domains] see RegExpFilter() 892 * @param {string} [domains] see RegExpFilter()
893 * @param {boolean} [thirdParty] see RegExpFilter() 893 * @param {boolean} [thirdParty] see RegExpFilter()
894 * @param {string} [sitekeys] see RegExpFilter() 894 * @param {string} [sitekeys] see RegExpFilter()
895 * @param {boolean} [collapse] 895 * @param {boolean} [collapse]
896 * defines whether the filter should collapse blocked content, can be null 896 * defines whether the filter should collapse blocked content, can be null
897 * @param {string} [csp] 897 * @param {string} [csp]
898 * Content Security Policy to inject when the filter matches 898 * Content Security Policy to inject when the filter matches
899 * @param {string} [rewrite] 899 * @param {?string} [rewrite]
900 * The rewrite expression 900 * The (optional) rule specifying how to rewrite the URL. See
kzar 2018/05/15 14:08:58 Mind making this comment useful? (Same below.)
hub 2018/05/15 16:16:31 Done.
kzar 2018/05/16 09:22:40 Thanks, looking way better now.
901 * BlockingFilter.prototype.rewrite.
901 * @constructor 902 * @constructor
902 * @augments RegExpFilter 903 * @augments RegExpFilter
903 */ 904 */
904 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, 905 function BlockingFilter(text, regexpSource, contentType, matchCase, domains,
905 thirdParty, sitekeys, collapse, csp, rewrite) 906 thirdParty, sitekeys, collapse, csp, rewrite)
906 { 907 {
907 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, 908 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
908 thirdParty, sitekeys); 909 thirdParty, sitekeys);
909 910
910 this.collapse = collapse; 911 this.collapse = collapse;
(...skipping 12 matching lines...) Expand all
923 */ 924 */
924 collapse: null, 925 collapse: null,
925 926
926 /** 927 /**
927 * Content Security Policy to inject for matching requests. 928 * Content Security Policy to inject for matching requests.
928 * @type {?string} 929 * @type {?string}
929 */ 930 */
930 csp: null, 931 csp: null,
931 932
932 /** 933 /**
933 * The rewrite expression 934 * The rule specifying how to rewrite the URL.
935 * The syntax is similar to the one of String.prototype.replace().
934 * @type {?string} 936 * @type {?string}
935 */ 937 */
936 rewrite: null, 938 rewrite: null,
937 939
938 /** 940 /**
939 * Rewrites an URL. 941 * Rewrites an URL.
940 * @param {string} url the URL to rewrite 942 * @param {string} url the URL to rewrite
941 * @return {string} the rewritten URL, or the original in case of failure 943 * @return {string} the rewritten URL, or the original in case of failure
942 */ 944 */
943 rewriteUrl(url) 945 rewriteUrl(url)
944 { 946 {
945 try 947 try
946 { 948 {
947 let rewrittenUrl = new URL(url.replace(this.regexp, this.rewrite), url); 949 let rewrittenUrl = new URL(url.replace(this.regexp, this.rewrite), url);
kzar 2018/05/17 12:56:06 I forgot to mention before, I thought how you did
hub 2018/05/17 12:58:39 thanks!
948 if (rewrittenUrl.origin == new URL(url).origin) 950 if (rewrittenUrl.origin == new URL(url).origin)
949 return rewrittenUrl.href; 951 return rewrittenUrl.href;
950 } 952 }
951 catch (e) 953 catch (e)
952 { 954 {
953 } 955 }
954 956
955 return url; 957 return url;
kzar 2018/05/15 14:24:57 Why do we return `url` on failure? Shouldn't we re
Sebastian Noack 2018/05/15 14:40:34 Even if no error is thrown and no origin change wa
kzar 2018/05/15 14:44:23 Not if we tweak the above logic, so we don't retur
Sebastian Noack 2018/05/15 14:51:02 Sure, we could add another check here, in order to
kzar 2018/05/15 14:53:58 Well it seems pointless to return the existing URL
Manish Jethani 2018/05/15 15:18:12 These are not the only cases in which the rewrite
hub 2018/05/15 16:16:31 The original idea is to not block the request in c
956 } 958 }
957 }); 959 });
958 960
959 /** 961 /**
960 * Class for whitelist filters 962 * Class for whitelist filters
961 * @param {string} text see Filter() 963 * @param {string} text see Filter()
962 * @param {string} regexpSource see RegExpFilter() 964 * @param {string} regexpSource see RegExpFilter()
963 * @param {number} [contentType] see RegExpFilter() 965 * @param {number} [contentType] see RegExpFilter()
964 * @param {boolean} [matchCase] see RegExpFilter() 966 * @param {boolean} [matchCase] see RegExpFilter()
965 * @param {string} [domains] see RegExpFilter() 967 * @param {string} [domains] see RegExpFilter()
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 */ 1113 */
1112 function ElemHideEmulationFilter(text, domains, selector) 1114 function ElemHideEmulationFilter(text, domains, selector)
1113 { 1115 {
1114 ElemHideBase.call(this, text, domains, selector); 1116 ElemHideBase.call(this, text, domains, selector);
1115 } 1117 }
1116 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1118 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1117 1119
1118 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1120 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1119 type: "elemhideemulation" 1121 type: "elemhideemulation"
1120 }); 1122 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld