diff --git a/packages/url/src/get-filename.js b/packages/url/src/get-filename.js index 2941f18fe07b4..d744a8da6bccf 100644 --- a/packages/url/src/get-filename.js +++ b/packages/url/src/get-filename.js @@ -13,6 +13,11 @@ */ export function getFilename( url ) { let filename; + + if ( ! url ) { + return; + } + try { filename = new URL( url, 'http://example.com' ).pathname .split( '/' ) diff --git a/packages/url/src/test/index.js b/packages/url/src/test/index.js index e258e112b2987..0051b9b89fc73 100644 --- a/packages/url/src/test/index.js +++ b/packages/url/src/test/index.js @@ -283,6 +283,8 @@ describe( 'getFilename', () => { ); expect( getFilename( 'a/path/' ) ).toBe( undefined ); expect( getFilename( '/' ) ).toBe( undefined ); + expect( getFilename( undefined ) ).toBe( undefined ); + expect( getFilename( null ) ).toBe( undefined ); } ); } );