浏览代码

fix: 修复isUrl判断错误bug #526

clddup 8 月之前
父节点
当前提交
3cd89bdd09
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      src/utils/is.ts

+ 6 - 3
src/utils/is.ts

@@ -95,9 +95,12 @@ export const isServer = typeof window === 'undefined'
 export const isClient = !isServer
 export const isClient = !isServer
 
 
 export const isUrl = (path: string): boolean => {
 export const isUrl = (path: string): boolean => {
-  const reg =
-    /(((^https?:(?:\/\/)?)(?:[-:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&%@.\w_]*)#?(?:[\w]*))?)$/
-  return reg.test(path)
+  try {
+    new URL(path)
+    return true
+  } catch (_error) {
+    return false
+  }
 }
 }
 
 
 export const isDark = (): boolean => {
 export const isDark = (): boolean => {