Left: | ||
Right: |
OLD | NEW |
---|---|
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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 text = text.substr(2); | 763 text = text.substr(2); |
764 } | 764 } |
765 | 765 |
766 let contentType = null; | 766 let contentType = null; |
767 let matchCase = null; | 767 let matchCase = null; |
768 let domains = null; | 768 let domains = null; |
769 let sitekeys = null; | 769 let sitekeys = null; |
770 let thirdParty = null; | 770 let thirdParty = null; |
771 let collapse = null; | 771 let collapse = null; |
772 let csp = null; | 772 let csp = null; |
773 let rewrite = null; | |
773 let options; | 774 let options; |
774 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); | 775 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); |
775 if (match) | 776 if (match) |
776 { | 777 { |
777 options = match[1].split(","); | 778 options = match[1].split(","); |
778 text = match.input.substr(0, match.index); | 779 text = match.input.substr(0, match.index); |
779 for (let option of options) | 780 for (let option of options) |
780 { | 781 { |
781 let value = null; | 782 let value = null; |
782 let separatorIndex = option.indexOf("="); | 783 let separatorIndex = option.indexOf("="); |
(...skipping 27 matching lines...) Expand all Loading... | |
810 else if (option == "THIRD_PARTY") | 811 else if (option == "THIRD_PARTY") |
811 thirdParty = true; | 812 thirdParty = true; |
812 else if (option == "~THIRD_PARTY") | 813 else if (option == "~THIRD_PARTY") |
813 thirdParty = false; | 814 thirdParty = false; |
814 else if (option == "COLLAPSE") | 815 else if (option == "COLLAPSE") |
815 collapse = true; | 816 collapse = true; |
816 else if (option == "~COLLAPSE") | 817 else if (option == "~COLLAPSE") |
817 collapse = false; | 818 collapse = false; |
818 else if (option == "SITEKEY" && value) | 819 else if (option == "SITEKEY" && value) |
819 sitekeys = value.toUpperCase(); | 820 sitekeys = value.toUpperCase(); |
821 else if (option == "REWRITE" && value) | |
822 rewrite = value; | |
820 else | 823 else |
821 return new InvalidFilter(origText, "filter_unknown_option"); | 824 return new InvalidFilter(origText, "filter_unknown_option"); |
822 } | 825 } |
823 } | 826 } |
824 | 827 |
825 try | 828 try |
826 { | 829 { |
827 if (blocking) | 830 if (blocking) |
828 { | 831 { |
829 if (csp && Filter.invalidCSPRegExp.test(csp)) | 832 if (csp && Filter.invalidCSPRegExp.test(csp)) |
830 return new InvalidFilter(origText, "filter_invalid_csp"); | 833 return new InvalidFilter(origText, "filter_invalid_csp"); |
831 | 834 |
832 return new BlockingFilter(origText, text, contentType, matchCase, domains, | 835 return new BlockingFilter(origText, text, contentType, matchCase, domains, |
833 thirdParty, sitekeys, collapse, csp); | 836 thirdParty, sitekeys, collapse, csp, rewrite); |
834 } | 837 } |
835 return new WhitelistFilter(origText, text, contentType, matchCase, domains, | 838 return new WhitelistFilter(origText, text, contentType, matchCase, domains, |
836 thirdParty, sitekeys); | 839 thirdParty, sitekeys); |
837 } | 840 } |
838 catch (e) | 841 catch (e) |
839 { | 842 { |
840 return new InvalidFilter(origText, "filter_invalid_regexp"); | 843 return new InvalidFilter(origText, "filter_invalid_regexp"); |
841 } | 844 } |
842 }; | 845 }; |
843 | 846 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 * @param {string} regexpSource see RegExpFilter() | 889 * @param {string} regexpSource see RegExpFilter() |
887 * @param {number} [contentType] see RegExpFilter() | 890 * @param {number} [contentType] see RegExpFilter() |
888 * @param {boolean} [matchCase] see RegExpFilter() | 891 * @param {boolean} [matchCase] see RegExpFilter() |
889 * @param {string} [domains] see RegExpFilter() | 892 * @param {string} [domains] see RegExpFilter() |
890 * @param {boolean} [thirdParty] see RegExpFilter() | 893 * @param {boolean} [thirdParty] see RegExpFilter() |
891 * @param {string} [sitekeys] see RegExpFilter() | 894 * @param {string} [sitekeys] see RegExpFilter() |
892 * @param {boolean} [collapse] | 895 * @param {boolean} [collapse] |
893 * defines whether the filter should collapse blocked content, can be null | 896 * defines whether the filter should collapse blocked content, can be null |
894 * @param {string} [csp] | 897 * @param {string} [csp] |
895 * Content Security Policy to inject when the filter matches | 898 * Content Security Policy to inject when the filter matches |
899 * @param {?string} [rewrite] | |
900 * The (optional) rule specifying how to rewrite the URL. See | |
901 * BlockingFilter.prototype.rewrite. | |
896 * @constructor | 902 * @constructor |
897 * @augments RegExpFilter | 903 * @augments RegExpFilter |
898 */ | 904 */ |
899 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, | 905 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
900 thirdParty, sitekeys, collapse, csp) | 906 thirdParty, sitekeys, collapse, csp, rewrite) |
901 { | 907 { |
902 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, | 908 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
903 thirdParty, sitekeys); | 909 thirdParty, sitekeys); |
904 | 910 |
905 this.collapse = collapse; | 911 this.collapse = collapse; |
906 this.csp = csp; | 912 this.csp = csp; |
913 this.rewrite = rewrite; | |
907 } | 914 } |
908 exports.BlockingFilter = BlockingFilter; | 915 exports.BlockingFilter = BlockingFilter; |
909 | 916 |
910 BlockingFilter.prototype = extend(RegExpFilter, { | 917 BlockingFilter.prototype = extend(RegExpFilter, { |
911 type: "blocking", | 918 type: "blocking", |
912 | 919 |
913 /** | 920 /** |
914 * Defines whether the filter should collapse blocked content. | 921 * Defines whether the filter should collapse blocked content. |
915 * Can be null (use the global preference). | 922 * Can be null (use the global preference). |
916 * @type {?boolean} | 923 * @type {?boolean} |
917 */ | 924 */ |
918 collapse: null, | 925 collapse: null, |
919 | 926 |
920 /** | 927 /** |
921 * Content Security Policy to inject for matching requests. | 928 * Content Security Policy to inject for matching requests. |
922 * @type {?string} | 929 * @type {?string} |
923 */ | 930 */ |
924 csp: null | 931 csp: null, |
932 | |
933 /** | |
934 * The rule specifying how to rewrite the URL. | |
935 * The syntax is similar to the one of String.prototype.replace(). | |
936 * @type {?string} | |
937 */ | |
938 rewrite: null, | |
939 | |
940 /** | |
941 * Rewrites an URL. | |
942 * @param {string} url the URL to rewrite | |
943 * @return {string} the rewritten URL, or the original in case of failure | |
944 */ | |
945 rewriteUrl(url) | |
946 { | |
947 try | |
948 { | |
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!
| |
950 if (rewrittenUrl.origin == new URL(url).origin) | |
951 return rewrittenUrl.href; | |
952 } | |
953 catch (e) | |
954 { | |
955 } | |
956 | |
957 return url; | |
958 } | |
925 }); | 959 }); |
926 | 960 |
927 /** | 961 /** |
928 * Class for whitelist filters | 962 * Class for whitelist filters |
929 * @param {string} text see Filter() | 963 * @param {string} text see Filter() |
930 * @param {string} regexpSource see RegExpFilter() | 964 * @param {string} regexpSource see RegExpFilter() |
931 * @param {number} [contentType] see RegExpFilter() | 965 * @param {number} [contentType] see RegExpFilter() |
932 * @param {boolean} [matchCase] see RegExpFilter() | 966 * @param {boolean} [matchCase] see RegExpFilter() |
933 * @param {string} [domains] see RegExpFilter() | 967 * @param {string} [domains] see RegExpFilter() |
934 * @param {boolean} [thirdParty] see RegExpFilter() | 968 * @param {boolean} [thirdParty] see RegExpFilter() |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 */ | 1113 */ |
1080 function ElemHideEmulationFilter(text, domains, selector) | 1114 function ElemHideEmulationFilter(text, domains, selector) |
1081 { | 1115 { |
1082 ElemHideBase.call(this, text, domains, selector); | 1116 ElemHideBase.call(this, text, domains, selector); |
1083 } | 1117 } |
1084 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1118 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1085 | 1119 |
1086 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1120 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1087 type: "elemhideemulation" | 1121 type: "elemhideemulation" |
1088 }); | 1122 }); |
OLD | NEW |