ソースを参照

Fixed isExternalLink

Taichi Masuyama 3 年 前
コミット
2762fd6d62

+ 10 - 2
packages/app/src/components/ReactMarkdownComponents/NextLink.tsx

@@ -8,8 +8,16 @@ const isAnchorLink = (href: string): boolean => {
 };
 };
 
 
 const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
 const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
-  const baseUrl = new URL(siteUrl ?? 'https://example.com');
-  const hrefUrl = new URL(href, baseUrl);
+  let baseUrl: URL;
+  let hrefUrl: URL;
+
+  try {
+    baseUrl = new URL(siteUrl ?? 'https://example.com');
+    hrefUrl = new URL(href, baseUrl);
+  }
+  catch {
+    return false;
+  }
 
 
   return baseUrl.host !== hrefUrl.host;
   return baseUrl.host !== hrefUrl.host;
 };
 };