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

Commit 36de6f1

Browse files
Claudio Procidafacebook-github-bot
authored andcommitted
Conditionally invokes URI.tryParseURI in OSS code
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
1 parent 9a9ccbd commit 36de6f1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/model/encoding/convertFromHTMLToContentBlocks.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,24 @@ const isValidAnchor = (node: Node) => {
161161
return false;
162162
}
163163
const anchorNode: HTMLAnchorElement = (node: any);
164-
return (
165-
!!anchorNode.href &&
166-
URI.tryParseURI(anchorNode.href) != null &&
167-
(anchorNode.protocol === 'http:' ||
168-
anchorNode.protocol === 'https:' ||
169-
anchorNode.protocol === 'mailto:' ||
170-
anchorNode.protocol === 'tel:')
171-
);
164+
165+
if (
166+
!anchorNode.href ||
167+
(anchorNode.protocol !== 'http:' &&
168+
anchorNode.protocol !== 'https:' &&
169+
anchorNode.protocol !== 'mailto:' &&
170+
anchorNode.protocol !== 'tel:')
171+
) {
172+
return false;
173+
}
174+
175+
try {
176+
// Just checking whether we can actually create a URI
177+
const _ = new URI(anchorNode.href);
178+
return true;
179+
} catch {
180+
return false;
181+
}
172182
};
173183

174184
/**

0 commit comments

Comments
 (0)