From a4c60733c0ca121be0473cf5d0ed019825fe430b Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 22 Jan 2020 14:45:02 -0500 Subject: [PATCH 1/4] Block Editor: Use WHATWG URL in place of legacy url module --- .../utils/transform-styles/transforms/url-rewrite.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/block-editor/src/utils/transform-styles/transforms/url-rewrite.js b/packages/block-editor/src/utils/transform-styles/transforms/url-rewrite.js index 4e0d07e4083d74..e74559515adaf4 100644 --- a/packages/block-editor/src/utils/transform-styles/transforms/url-rewrite.js +++ b/packages/block-editor/src/utils/transform-styles/transforms/url-rewrite.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { parse, resolve } from 'url'; - /** * Return `true` if the given path is http/https. * @@ -62,10 +57,7 @@ function isValidURL( meta ) { * @return {string} the full path to the file */ function getResourcePath( str, baseURL ) { - const pathname = parse( str ).pathname; - const filePath = resolve( baseURL, pathname ); - - return filePath; + return new URL( str, baseURL ).toString(); } /** From 2f927f4521fc6d70aac69d16d2221fdafdb1a362 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 22 Jan 2020 14:45:25 -0500 Subject: [PATCH 2/4] Block Library: Use WHATWG URL in place of legacy url module --- package-lock.json | 10 ++++++---- packages/block-library/package.json | 3 +-- packages/block-library/src/embed/embed-preview.js | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42dabf49da7d7b..612ac2252c53b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10136,8 +10136,7 @@ "lodash": "^4.17.15", "memize": "^1.0.5", "moment": "^2.22.1", - "tinycolor2": "^1.4.1", - "url": "^0.11.0" + "tinycolor2": "^1.4.1" } }, "@wordpress/block-serialization-default-parser": { @@ -32532,7 +32531,8 @@ "querystring": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", - "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=" + "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=", + "dev": true }, "querystring-es3": { "version": "0.2.1", @@ -39363,6 +39363,7 @@ "version": "0.11.0", "resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz", "integrity": "sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=", + "dev": true, "requires": { "punycode": "1.3.2", "querystring": "0.2.0" @@ -39371,7 +39372,8 @@ "punycode": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", - "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=" + "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=", + "dev": true } } }, diff --git a/packages/block-library/package.json b/packages/block-library/package.json index 68acaac0d89555..2a19ca9a97c52b 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -55,8 +55,7 @@ "lodash": "^4.17.15", "memize": "^1.0.5", "moment": "^2.22.1", - "tinycolor2": "^1.4.1", - "url": "^0.11.0" + "tinycolor2": "^1.4.1" }, "publishConfig": { "access": "public" diff --git a/packages/block-library/src/embed/embed-preview.js b/packages/block-library/src/embed/embed-preview.js index db139e5292b7bd..419ef17c7bb115 100644 --- a/packages/block-library/src/embed/embed-preview.js +++ b/packages/block-library/src/embed/embed-preview.js @@ -7,7 +7,6 @@ import { getPhotoHtml } from './util'; /** * External dependencies */ -import { parse } from 'url'; import { includes } from 'lodash'; import classnames from 'classnames/dedupe'; @@ -69,7 +68,7 @@ class EmbedPreview extends Component { const { interactive } = this.state; const html = 'photo' === type ? getPhotoHtml( preview ) : preview.html; - const parsedHost = parse( url ).host.split( '.' ); + const parsedHost = new URL( url ).host.split( '.' ); const parsedHostBaseUrl = parsedHost .splice( parsedHost.length - 2, parsedHost.length - 1 ) .join( '.' ); From 9bed708183c55de5cd27ad70da33836fa51d6c86 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 22 Jan 2020 14:45:39 -0500 Subject: [PATCH 3/4] E2E Test Utils: Block Editor: Use WHATWG URL in place of legacy url module --- packages/e2e-test-utils/src/create-url.js | 1 - packages/e2e-test-utils/src/is-current-url.js | 5 ----- 2 files changed, 6 deletions(-) diff --git a/packages/e2e-test-utils/src/create-url.js b/packages/e2e-test-utils/src/create-url.js index 5bc9e6df3a59d4..d608e75e306ae9 100644 --- a/packages/e2e-test-utils/src/create-url.js +++ b/packages/e2e-test-utils/src/create-url.js @@ -2,7 +2,6 @@ * External dependencies */ import { join } from 'path'; -import { URL } from 'url'; /** * Internal dependencies diff --git a/packages/e2e-test-utils/src/is-current-url.js b/packages/e2e-test-utils/src/is-current-url.js index 80058d1225281f..002ce83b4c1e8b 100644 --- a/packages/e2e-test-utils/src/is-current-url.js +++ b/packages/e2e-test-utils/src/is-current-url.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { URL } from 'url'; - /** * Internal dependencies */ From 26a0dbc0bd835961ad7e3644e2339cab020766ab Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 22 Jan 2020 14:45:55 -0500 Subject: [PATCH 4/4] E2E Tests: Use WHATWG URL in place of legacy url module --- packages/e2e-tests/specs/editor/various/preview.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/preview.test.js b/packages/e2e-tests/specs/editor/various/preview.test.js index 53130fe8d2eba6..c45e7cced2e7b4 100644 --- a/packages/e2e-tests/specs/editor/various/preview.test.js +++ b/packages/e2e-tests/specs/editor/various/preview.test.js @@ -2,7 +2,6 @@ * External dependencies */ import { last } from 'lodash'; -import { parse } from 'url'; /** * WordPress dependencies @@ -187,9 +186,9 @@ describe( 'Preview', () => { expect( previewTitle ).toBe( 'Hello World! And more.' ); // Published preview URL should include ID and nonce parameters. - const { query } = parse( previewPage.url(), true ); - expect( query ).toHaveProperty( 'preview_id' ); - expect( query ).toHaveProperty( 'preview_nonce' ); + const { searchParams } = new URL( previewPage.url() ); + expect( searchParams.has( 'preview_id' ) ).toBe( true ); + expect( searchParams.has( 'preview_nonce' ) ).toBe( true ); // Return to editor. Previewing already-autosaved preview tab should // reuse the opened tab, skipping interstitial. This resolves an edge