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

Side by Side Diff: lib/content/snippets.js

Issue 30013555: Issue 7294 - Pass necessary functions to strip-fetch-query-parameter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Simplify Created Feb. 21, 2019, 9 a.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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
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")
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 return fetch_.apply(this, args);
a.giammarchi 2019/02/21 10:26:58 cannot we just `return fetch_(...args)` after late
Manish Jethani 2019/02/21 10:35:04 I don't see why we should assume anything about th
876 }; 879 };
877 } 880 }
878 881
879 exports["strip-fetch-query-parameter"] = 882 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter,
880 makeInjector(stripFetchQueryParameter); 883 toRegExp, regexEscape);
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