massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / node_modules / node-fetch / lib / index.es.js
index 61906c95981eae213a20dbca82d8f9178ade64bd..79f70d356bb913dc2c8fe4f3181ad9105d44850b 100644 (file)
@@ -3,6 +3,7 @@ process.emitWarning("The .es.js file is deprecated. Use .mjs instead.");
 import Stream from 'stream';
 import http from 'http';
 import Url from 'url';
+import whatwgUrl from 'whatwg-url';
 import https from 'https';
 import zlib from 'zlib';
 
@@ -1137,11 +1138,32 @@ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
 });
 
 const INTERNALS$2 = Symbol('Request internals');
+const URL = Url.URL || whatwgUrl.URL;
 
 // fix an issue where "format", "parse" aren't a named export for node <10
 const parse_url = Url.parse;
 const format_url = Url.format;
 
+/**
+ * Wrapper around `new URL` to handle arbitrary URLs
+ *
+ * @param  {string} urlStr
+ * @return {void}
+ */
+function parseURL(urlStr) {
+       /*
+       Check whether the URL is absolute or not
+               Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
+       Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
+ */
+       if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
+               urlStr = new URL(urlStr).toString();
+       }
+
+       // Fallback to old implementation for arbitrary URLs
+       return parse_url(urlStr);
+}
+
 const streamDestructionSupported = 'destroy' in Stream.Readable.prototype;
 
 /**
@@ -1178,14 +1200,14 @@ class Request {
                                // in order to support Node.js' Url objects; though WHATWG's URL objects
                                // will fall into this branch also (since their `toString()` will return
                                // `href` property anyway)
-                               parsedURL = parse_url(input.href);
+                               parsedURL = parseURL(input.href);
                        } else {
                                // coerce input to a string before attempting to parse
-                               parsedURL = parse_url(`${input}`);
+                               parsedURL = parseURL(`${input}`);
                        }
                        input = {};
                } else {
-                       parsedURL = parse_url(input.url);
+                       parsedURL = parseURL(input.url);
                }
 
                let method = init.method || input.method || 'GET';