Skip to content

Commit

Permalink
Handle syntax errors from any invalid URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwight committed Nov 1, 2019
1 parent 9fb6eb2 commit 1c73ad4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/wpcom-block-editor/src/common/coblocks-preview-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const blocksToFilter = [ 'coblocks/masonry-gallery', 'coblocks/gallery-stacked',
const isSimpleSite = !! window.wpcomGutenberg.pluginVersion;

function updateUrl( url, version ) {
const updatedPath = new URL( url ).pathname.replace(
/coblocks\/dist/,
`coblocks/${ version }/dist`
);
let updatedPath;

try {
updatedPath = new URL( url ).pathname.replace( /coblocks\/dist/, `coblocks/${ version }/dist` );
} catch ( e ) {
return false;
}

return `https://s0.wp.com${ updatedPath }`;
}

Expand Down

0 comments on commit 1c73ad4

Please sign in to comment.