Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
854 | 854 |
855 /** | 855 /** |
856 * Strips a query string parameter from <code>fetch()</code> calls. | 856 * Strips a query string parameter from <code>fetch()</code> calls. |
857 * | 857 * |
858 * @param {string} name The name of the parameter. | 858 * @param {string} name The name of the parameter. |
859 * @param {?string} [urlPattern] An optional pattern that the URL must match. | 859 * @param {?string} [urlPattern] An optional pattern that the URL must match. |
860 */ | 860 */ |
861 function stripFetchQueryParameter(name, urlPattern = null) | 861 function stripFetchQueryParameter(name, urlPattern = null) |
862 { | 862 { |
863 let fetch_ = window.fetch; | 863 let fetch_ = window.fetch; |
864 if (typeof fetch_ != "function") | 864 if (typeof fetch_ != "function") |
Manish Jethani
2019/02/21 08:15:43
Being defensive, just in case fetch does't exist (
| |
865 return; | 865 return; |
866 | 866 |
867 let urlRegExp = urlPattern ? toRegExp(urlPattern) : null; | 867 let urlRegExp = urlPattern ? toRegExp(urlPattern) : null; |
868 window.fetch = function fetch(...args) | 868 window.fetch = function fetch(...args) |
869 { | 869 { |
870 let [source] = args; | 870 let [source] = args; |
871 if (typeof source == "string" && | 871 if (typeof source == "string" && |
872 (!urlRegExp || urlRegExp.test(source))) | 872 (!urlRegExp || urlRegExp.test(source))) |
873 { | 873 { |
874 let url = new URL(source); | 874 let url = new URL(source); |
875 url.searchParams.delete(name); | 875 url.searchParams.delete(name); |
876 args[0] = url.href; | 876 args[0] = url.href; |
877 } | 877 } |
878 | 878 return fetch_.apply(this, args); |
879 return (() => {}).apply.call(fetch_, this, args); | |
Manish Jethani
2019/02/21 08:15:43
This is because you can have a function with a nul
a.giammarchi
2019/02/21 08:27:35
IMO this is super ugly and it doesn't prevent poss
Manish Jethani
2019/02/21 08:57:16
This is not about overrides but rather about the p
Manish Jethani
2019/02/21 09:00:36
Done.
| |
880 }; | 879 }; |
881 } | 880 } |
882 | 881 |
883 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, | 882 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, |
884 toRegExp, regexEscape); | 883 toRegExp, regexEscape); |
LEFT | RIGHT |