Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: fix crash if embed url is invalid or empty

Abdullah Atta656f87e3c6a7
diff --git a/packages/editor/src/extensions/embed/component.tsx b/packages/editor/src/extensions/embed/component.tsx
index 999c570bf..4dd58422f 100644
--- a/packages/editor/src/extensions/embed/component.tsx
+++ b/packages/editor/src/extensions/embed/component.tsx
@@ -179,15 +179,19 @@ function getSandboxFeatures(src: string) {
}
function isYouTubeEmbed(urlString: string) {
- const url = new URL(urlString);
- return (
- (url.hostname === "www.youtube.com" ||
- url.hostname === "youtube.com" ||
- url.hostname === "m.youtube.com" ||
- url.hostname === "www.youtube-nocookie.com" ||
- url.hostname === "youtube-nocookie.com") &&
- url.pathname.startsWith("/embed/")
- );
+ try {
+ const url = new URL(urlString);
+ return (
+ (url.hostname === "www.youtube.com" ||
+ url.hostname === "youtube.com" ||
+ url.hostname === "m.youtube.com" ||
+ url.hostname === "www.youtube-nocookie.com" ||
+ url.hostname === "youtube-nocookie.com") &&
+ url.pathname.startsWith("/embed/")
+ );
+ } catch {
+ return false;
+ }
}
function isTwitterX(src: string) {