Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Conditionally invokes URI.tryParseURI in OSS code
Browse files Browse the repository at this point in the history
Summary:
Conditionally invokes URI.tryParseURI in OSS code because it's not available in fbjs.

I am on the fence on this one, we need it internally but we can't break OSS consumers of Draft. I think the optional chaining operator with a fallback is a pretty conservative option, however it does look clowny af.

Differential Revision: D22722736

fbshipit-source-id: d8630899b88bd0961ed2e8be86ab25d4369d40d6
  • Loading branch information
Claudio Procida authored and facebook-github-bot committed Jul 24, 2020
1 parent 9a9ccbd commit 36de6f1
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/model/encoding/convertFromHTMLToContentBlocks.js
Expand Up @@ -161,14 +161,24 @@ const isValidAnchor = (node: Node) => {
return false;
}
const anchorNode: HTMLAnchorElement = (node: any);
return (
!!anchorNode.href &&
URI.tryParseURI(anchorNode.href) != null &&
(anchorNode.protocol === 'http:' ||
anchorNode.protocol === 'https:' ||
anchorNode.protocol === 'mailto:' ||
anchorNode.protocol === 'tel:')
);

if (
!anchorNode.href ||
(anchorNode.protocol !== 'http:' &&
anchorNode.protocol !== 'https:' &&
anchorNode.protocol !== 'mailto:' &&
anchorNode.protocol !== 'tel:')
) {
return false;
}

try {
// Just checking whether we can actually create a URI
const _ = new URI(anchorNode.href);
return true;
} catch {
return false;
}
};

/**
Expand Down

0 comments on commit 36de6f1

Please sign in to comment.