Bug 1544170 Part 4 - Don't infinitely recurse in newChannelForURL on failure, r=loganfsmyth.

Differential Revision: https://phabricator.services.mozilla.com/D27411

--HG--
extra : rebase_source : 658df8227afa78826ef32b63f87e7c0f9554bda2
This commit is contained in:
Brian Hackett 2019-04-12 16:37:00 -10:00
Родитель ee403cec34
Коммит 18578fbd02
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -642,7 +642,7 @@ function mainThreadFetch(urlIn, aOptions = { loadFromCache: true,
* @param {Object} options - The options object passed to @method fetch.
* @return {nsIChannel} - The newly created channel. Throws on failure.
*/
function newChannelForURL(url, { policy, window, principal }) {
function newChannelForURL(url, { policy, window, principal }, recursing = false) {
const securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
let uri;
@ -689,11 +689,17 @@ function newChannelForURL(url, { policy, window, principal }) {
try {
return NetUtil.newChannel(channelOptions);
} catch (e) {
// Don't infinitely recurse if newChannel keeps throwing.
if (recursing) {
throw e;
}
// In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel()
// can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't
// supported by Windows, so we also need to handle the exception here if
// parsing the URL above doesn't throw.
return newChannelForURL("file://" + url, { policy, window, principal });
return newChannelForURL("file://" + url, { policy, window, principal },
/* recursing */ true);
}
}