From 09f22e5b242fed0714b4cbcffe2405c1f1f11a75 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 30 Aug 2021 13:51:11 +0000 Subject: [PATCH] External Libraries: Update `whatwg-fetch` package to version 3.6.2. This matches the version used in the Gutenberg project. While WordPress core no longer depends on this polyfill as of [50934], this brings the latest updates of the library to anyone still utilizing it. For a full list of changes in this update, see the `whatwg-fetch` GitHub: https://github.com/github/fetch/compare/v3.0.0...v3.6.2 Follow-up to [43719], [50934]. Props hareesh-pillai, rsiddharth, desrosj. Fixes #53929. Built from https://develop.svn.wordpress.org/trunk@51692 git-svn-id: http://core.svn.wordpress.org/trunk@51298 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../js/dist/vendor/wp-polyfill-fetch.js | 157 ++++++++++++++---- .../js/dist/vendor/wp-polyfill-fetch.min.js | 2 +- wp-includes/script-loader.php | 2 +- wp-includes/version.php | 2 +- 4 files changed, 126 insertions(+), 37 deletions(-) diff --git a/wp-includes/js/dist/vendor/wp-polyfill-fetch.js b/wp-includes/js/dist/vendor/wp-polyfill-fetch.js index f9b44fd7c5..8c3269e3c7 100644 --- a/wp-includes/js/dist/vendor/wp-polyfill-fetch.js +++ b/wp-includes/js/dist/vendor/wp-polyfill-fetch.js @@ -4,12 +4,17 @@ (factory((global.WHATWGFetch = {}))); }(this, (function (exports) { 'use strict'; + var global = + (typeof globalThis !== 'undefined' && globalThis) || + (typeof self !== 'undefined' && self) || + (typeof global !== 'undefined' && global); + var support = { - searchParams: 'URLSearchParams' in self, - iterable: 'Symbol' in self && 'iterator' in Symbol, + searchParams: 'URLSearchParams' in global, + iterable: 'Symbol' in global && 'iterator' in Symbol, blob: - 'FileReader' in self && - 'Blob' in self && + 'FileReader' in global && + 'Blob' in global && (function() { try { new Blob(); @@ -18,8 +23,8 @@ return false } })(), - formData: 'FormData' in self, - arrayBuffer: 'ArrayBuffer' in self + formData: 'FormData' in global, + arrayBuffer: 'ArrayBuffer' in global }; function isDataView(obj) { @@ -50,8 +55,8 @@ if (typeof name !== 'string') { name = String(name); } - if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) { - throw new TypeError('Invalid character in header field name') + if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') { + throw new TypeError('Invalid character in header field name: "' + name + '"') } return name.toLowerCase() } @@ -215,6 +220,17 @@ this.bodyUsed = false; this._initBody = function(body) { + /* + fetch-mock wraps the Response object in an ES6 Proxy to + provide useful test harness features such as flush. However, on + ES5 browsers without fetch or Proxy support pollyfills must be used; + the proxy-pollyfill is unable to proxy an attribute unless it exists + on the object before the Proxy is created. This change ensures + Response.bodyUsed exists on the instance, while maintaining the + semantic of setting Request.bodyUsed in the constructor before + _initBody is called. + */ + this.bodyUsed = this.bodyUsed; this._bodyInit = body; if (!body) { this._bodyText = ''; @@ -267,7 +283,20 @@ this.arrayBuffer = function() { if (this._bodyArrayBuffer) { - return consumed(this) || Promise.resolve(this._bodyArrayBuffer) + var isConsumed = consumed(this); + if (isConsumed) { + return isConsumed + } + if (ArrayBuffer.isView(this._bodyArrayBuffer)) { + return Promise.resolve( + this._bodyArrayBuffer.buffer.slice( + this._bodyArrayBuffer.byteOffset, + this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength + ) + ) + } else { + return Promise.resolve(this._bodyArrayBuffer) + } } else { return this.blob().then(readBlobAsArrayBuffer) } @@ -313,6 +342,10 @@ } function Request(input, options) { + if (!(this instanceof Request)) { + throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.') + } + options = options || {}; var body = options.body; @@ -349,6 +382,21 @@ throw new TypeError('Body not allowed for GET or HEAD requests') } this._initBody(body); + + if (this.method === 'GET' || this.method === 'HEAD') { + if (options.cache === 'no-store' || options.cache === 'no-cache') { + // Search for a '_' parameter in the query string + var reParamSearch = /([?&])_=[^&]*/; + if (reParamSearch.test(this.url)) { + // If it already exists then set the value with the current time + this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime()); + } else { + // Otherwise add a new '_' parameter to the end with the current time + var reQueryString = /\?/; + this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime(); + } + } + } } Request.prototype.clone = function() { @@ -376,20 +424,31 @@ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space // https://tools.ietf.org/html/rfc7230#section-3.2 var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); - preProcessedHeaders.split(/\r?\n/).forEach(function(line) { - var parts = line.split(':'); - var key = parts.shift().trim(); - if (key) { - var value = parts.join(':').trim(); - headers.append(key, value); - } - }); + // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill + // https://github.com/github/fetch/issues/748 + // https://github.com/zloirock/core-js/issues/751 + preProcessedHeaders + .split('\r') + .map(function(header) { + return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header + }) + .forEach(function(line) { + var parts = line.split(':'); + var key = parts.shift().trim(); + if (key) { + var value = parts.join(':').trim(); + headers.append(key, value); + } + }); return headers } Body.call(Request.prototype); function Response(bodyInit, options) { + if (!(this instanceof Response)) { + throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.') + } if (!options) { options = {}; } @@ -397,7 +456,7 @@ this.type = 'default'; this.status = options.status === undefined ? 200 : options.status; this.ok = this.status >= 200 && this.status < 300; - this.statusText = 'statusText' in options ? options.statusText : 'OK'; + this.statusText = options.statusText === undefined ? '' : '' + options.statusText; this.headers = new Headers(options.headers); this.url = options.url || ''; this._initBody(bodyInit); @@ -430,7 +489,7 @@ return new Response(null, {status: status, headers: {location: url}}) }; - exports.DOMException = self.DOMException; + exports.DOMException = global.DOMException; try { new exports.DOMException(); } catch (err) { @@ -466,22 +525,38 @@ }; options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); var body = 'response' in xhr ? xhr.response : xhr.responseText; - resolve(new Response(body, options)); + setTimeout(function() { + resolve(new Response(body, options)); + }, 0); }; xhr.onerror = function() { - reject(new TypeError('Network request failed')); + setTimeout(function() { + reject(new TypeError('Network request failed')); + }, 0); }; xhr.ontimeout = function() { - reject(new TypeError('Network request failed')); + setTimeout(function() { + reject(new TypeError('Network request failed')); + }, 0); }; xhr.onabort = function() { - reject(new exports.DOMException('Aborted', 'AbortError')); + setTimeout(function() { + reject(new exports.DOMException('Aborted', 'AbortError')); + }, 0); }; - xhr.open(request.method, request.url, true); + function fixUrl(url) { + try { + return url === '' && global.location.href ? global.location.href : url + } catch (e) { + return url + } + } + + xhr.open(request.method, fixUrl(request.url), true); if (request.credentials === 'include') { xhr.withCredentials = true; @@ -489,13 +564,27 @@ xhr.withCredentials = false; } - if ('responseType' in xhr && support.blob) { - xhr.responseType = 'blob'; + if ('responseType' in xhr) { + if (support.blob) { + xhr.responseType = 'blob'; + } else if ( + support.arrayBuffer && + request.headers.get('Content-Type') && + request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1 + ) { + xhr.responseType = 'arraybuffer'; + } } - request.headers.forEach(function(value, name) { - xhr.setRequestHeader(name, value); - }); + if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) { + Object.getOwnPropertyNames(init.headers).forEach(function(name) { + xhr.setRequestHeader(name, normalizeValue(init.headers[name])); + }); + } else { + request.headers.forEach(function(value, name) { + xhr.setRequestHeader(name, value); + }); + } if (request.signal) { request.signal.addEventListener('abort', abortXhr); @@ -514,11 +603,11 @@ fetch.polyfill = true; - if (!self.fetch) { - self.fetch = fetch; - self.Headers = Headers; - self.Request = Request; - self.Response = Response; + if (!global.fetch) { + global.fetch = fetch; + global.Headers = Headers; + global.Request = Request; + global.Response = Response; } exports.Headers = Headers; diff --git a/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js b/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js index f81355b26b..28f171e5ef 100644 --- a/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js +++ b/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.WHATWGFetch={})}(this,function(a){"use strict";var e,r,o="URLSearchParams"in self,n="Symbol"in self&&"iterator"in Symbol,h="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in self,s="ArrayBuffer"in self;function u(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function f(t){return t="string"!=typeof t?String(t):t}function t(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function d(e){this.map={},e instanceof d?e.forEach(function(t,e){this.append(e,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(r){return new Promise(function(t,e){r.onload=function(){t(r.result)},r.onerror=function(){e(r.error)}})}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function l(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(t){var e;(this._bodyInit=t)?"string"==typeof t?this._bodyText=t:h&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:o&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&h&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=l(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||r(t))?this._bodyArrayBuffer=l(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},h&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r=c(this);if(r)return r;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=p(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o '0.13.7', 'moment' => '2.29.1', 'lodash' => '4.17.19', - 'wp-polyfill-fetch' => '3.0.0', + 'wp-polyfill-fetch' => '3.6.2', 'wp-polyfill-formdata' => '4.0.0', 'wp-polyfill-node-contains' => '3.105.0', 'wp-polyfill-url' => '3.6.4', diff --git a/wp-includes/version.php b/wp-includes/version.php index 945fc3a7af..022527b8cf 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51689'; +$wp_version = '5.9-alpha-51692'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.