From 3cd89bdd09ee45d97d1ea41a5ee7686ca56c4ff2 Mon Sep 17 00:00:00 2001 From: clddup <105873086+clddup@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:54:42 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DisUrl=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=94=99=E8=AF=AFbug=20=20#526?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/is.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/is.ts b/src/utils/is.ts index 8ac2e50..1651420 100644 --- a/src/utils/is.ts +++ b/src/utils/is.ts @@ -95,9 +95,12 @@ export const isServer = typeof window === 'undefined' export const isClient = !isServer 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 => {