From 7fa0255d62c861147953c08b3a18fd5d3618732d Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 18 Apr 2018 16:25:39 +0100 Subject: [PATCH] work around IE XHR bug with '' URL Fixes #28 Fix when running on Firefox with fetchPonyfill (and any other error cases) --- fetch.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fetch.js b/fetch.js index f2f466d7..1210deaf 100644 --- a/fetch.js +++ b/fetch.js @@ -342,6 +342,14 @@ Request.prototype.clone = function() { return new Request(this, { body: this._bodyInit }) } + + function fixUrl(url) { + try { + return url === '' && self.location.href ? self.location.href : url + } catch(e) { + return url; + } + } function decode(body) { var form = new FormData() @@ -443,7 +451,7 @@ reject(new TypeError('Network request failed')) } - xhr.open(request.method, request.url, true) + xhr.open(request.method, fixUrl(request.url), true) if (request.credentials === 'include') { xhr.withCredentials = true