Skip to content

Commit

Permalink
Framework: Use WHATWG URL in place of legacy url module (#19823)
Browse files Browse the repository at this point in the history
* Block Editor: Use WHATWG URL in place of legacy url module

* Block Library: Use WHATWG URL in place of legacy url module

* E2E Test Utils: Block Editor: Use WHATWG URL in place of legacy url module

* E2E Tests: Use WHATWG URL in place of legacy url module
  • Loading branch information
aduth authored Mar 12, 2020
1 parent 4f3b69e commit 3b63be6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 deletions.
10 changes: 6 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { parse, resolve } from 'url';

/**
* Return `true` if the given path is http/https.
*
Expand Down Expand Up @@ -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();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getPhotoHtml } from './util';
/**
* External dependencies
*/
import { parse } from 'url';
import { includes } from 'lodash';
import classnames from 'classnames/dedupe';

Expand Down Expand Up @@ -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( '.' );
Expand Down
1 change: 0 additions & 1 deletion packages/e2e-test-utils/src/create-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { join } from 'path';
import { URL } from 'url';

/**
* Internal dependencies
Expand Down
5 changes: 0 additions & 5 deletions packages/e2e-test-utils/src/is-current-url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { URL } from 'url';

/**
* Internal dependencies
*/
Expand Down
7 changes: 3 additions & 4 deletions packages/e2e-tests/specs/editor/various/preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { last } from 'lodash';
import { parse } from 'url';

/**
* WordPress dependencies
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3b63be6

Please sign in to comment.