| 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 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") | |
|
Manish Jethani
2019/02/21 08:15:43
Being defensive, just in case fetch does't exist (
| |
| 865 return; | |
| 866 | |
| 864 let urlRegExp = urlPattern ? toRegExp(urlPattern) : null; | 867 let urlRegExp = urlPattern ? toRegExp(urlPattern) : null; |
| 865 window.fetch = function fetch(...args) | 868 window.fetch = function fetch(...args) |
| 866 { | 869 { |
| 867 let [source] = args; | 870 let [source] = args; |
| 868 if (typeof source == "string" && | 871 if (typeof source == "string" && |
| 869 (!urlRegExp || urlRegExp.test(source))) | 872 (!urlRegExp || urlRegExp.test(source))) |
| 870 { | 873 { |
| 871 let url = new URL(source); | 874 let url = new URL(source); |
| 872 url.searchParams.delete(name); | 875 url.searchParams.delete(name); |
| 873 args[0] = url.href; | 876 args[0] = url.href; |
| 874 } | 877 } |
| 875 return fetch_.apply(this, args); | 878 |
| 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.
| |
| 876 }; | 880 }; |
| 877 } | 881 } |
| 878 | 882 |
| 879 exports["strip-fetch-query-parameter"] = | 883 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, |
| 880 makeInjector(stripFetchQueryParameter); | 884 toRegExp, regexEscape); |
| OLD | NEW |