From bc6ee2edc9f16791b2bb64049c2c34ed83796d29 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sat, 6 Apr 2024 00:38:39 +0100
Subject: fix: Only consider text as URL in editor card if it has an http
 protocol. Fixes #86

---
 apps/web/components/dashboard/bookmarks/EditorCard.tsx | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'apps/web/components/dashboard/bookmarks/EditorCard.tsx')

diff --git a/apps/web/components/dashboard/bookmarks/EditorCard.tsx b/apps/web/components/dashboard/bookmarks/EditorCard.tsx
index 28686e6c..6858255a 100644
--- a/apps/web/components/dashboard/bookmarks/EditorCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/EditorCard.tsx
@@ -67,7 +67,10 @@ export default function EditorCard({ className }: { className?: string }) {
   const onSubmit: SubmitHandler<z.infer<typeof formSchema>> = (data) => {
     const text = data.text.trim();
     try {
-      new URL(text);
+      const url = new URL(text);
+      if (url.protocol != "http:" && url.protocol != "https:") {
+        throw new Error("Invalid URL");
+      }
       mutate({ type: "link", url: text });
     } catch (e) {
       // Not a URL
-- 
cgit v1.2.3-70-g09d2

