From cfd1479ac628f3a8b87775d616d77c2e2fb26945 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 26 Mar 2023 01:20:46 +0800 Subject: [PATCH] fix: fix url which without protocol will not been correct parse --- client/web/plugins/com.msgbyte.webview/package.json | 3 ++- .../src/group/GroupWebPanelRender.tsx | 10 +++++++++- pnpm-lock.yaml | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/web/plugins/com.msgbyte.webview/package.json b/client/web/plugins/com.msgbyte.webview/package.json index bfd43feb..fe8f581a 100644 --- a/client/web/plugins/com.msgbyte.webview/package.json +++ b/client/web/plugins/com.msgbyte.webview/package.json @@ -4,6 +4,7 @@ "version": "0.0.0", "private": true, "dependencies": { - "script_sanitize": "^1.2.6" + "script_sanitize": "^1.2.6", + "url-regex": "^5.0.0" } } diff --git a/client/web/plugins/com.msgbyte.webview/src/group/GroupWebPanelRender.tsx b/client/web/plugins/com.msgbyte.webview/src/group/GroupWebPanelRender.tsx index ad425999..21944cb0 100644 --- a/client/web/plugins/com.msgbyte.webview/src/group/GroupWebPanelRender.tsx +++ b/client/web/plugins/com.msgbyte.webview/src/group/GroupWebPanelRender.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Translate } from '../translate'; import { WebviewKeepAlive } from '@capital/component'; +import urlRegex from 'url-regex'; const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { const panelInfo = props.panelInfo; @@ -9,7 +10,14 @@ const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { return
{Translate.notfound}
; } - const url = panelInfo?.meta?.url; + let url = String(panelInfo?.meta?.url); + if ( + !url.includes('://') && + urlRegex({ exact: true, strict: false }).test(url) + ) { + // 不包含协议, 但是是个网址 + url = 'https://' + url; + } return ( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 93ced083..722062bf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -829,8 +829,10 @@ importers: client/web/plugins/com.msgbyte.webview: specifiers: script_sanitize: ^1.2.6 + url-regex: ^5.0.0 dependencies: script_sanitize: 1.2.6 + url-regex: 5.0.0 client/web/plugins/com.msgbyte.wenshushu: specifiers: @@ -844,6 +846,9 @@ importers: devDependencies: react: 18.2.0 + packages/types: + specifiers: {} + server: specifiers: '@babel/helper-compilation-targets': ^7.18.2