diff --git a/site/examples/embeds.tsx b/site/examples/embeds.tsx index 47e5951aff..248becff1e 100644 --- a/site/examples/embeds.tsx +++ b/site/examples/embeds.tsx @@ -41,9 +41,24 @@ const Element = props => { } } +const allowedSchemes = ['http:', 'https:'] + const VideoElement = ({ attributes, children, element }) => { const editor = useSlateStatic() const { url } = element + + const safeUrl = useMemo(() => { + let parsedUrl: URL = null + try { + parsedUrl = new URL(url) + // eslint-disable-next-line no-empty + } catch {} + if (parsedUrl && allowedSchemes.includes(parsedUrl.protocol)) { + return parsedUrl.href + } + return 'about:blank' + }, [url]) + return (
@@ -54,7 +69,7 @@ const VideoElement = ({ attributes, children, element }) => { }} >