Skip to content

Commit

Permalink
Don't use window dom methods for checking if we have a link response
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki committed May 16, 2018
1 parent 75f9115 commit d94f53a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions core-blocks/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export function getPreview( state, url ) {
return preview;
}

// this won't execute any scripts, so it's safe to check if the returned preview is just a single link
const linkCheck = document.createElement( 'div' );
linkCheck.innerHTML = preview.html;
const oEmbedLinkCheck = `<a href="${ url }">${ url }</a>`;

if ( 1 === linkCheck.children.length && 'A' === linkCheck.children[ 0 ].nodeName && 0 === linkCheck.children[ 0 ].children.length ) {
// single link, no children, it's oEmbed being helpful and creating a link for us, not actually embedding content
if ( oEmbedLinkCheck === preview.html ) {
// just a link to the url, it's oEmbed being helpful and creating a link for us, not actually embedding content
return false;
}

Expand Down

0 comments on commit d94f53a

Please sign in to comment.