fix: fix url which without protocol will not been correct parse

pull/90/head
moonrailgun 2 years ago
parent 178acf5903
commit cfd1479ac6

@ -4,6 +4,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"script_sanitize": "^1.2.6" "script_sanitize": "^1.2.6",
"url-regex": "^5.0.0"
} }
} }

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import { Translate } from '../translate'; import { Translate } from '../translate';
import { WebviewKeepAlive } from '@capital/component'; import { WebviewKeepAlive } from '@capital/component';
import urlRegex from 'url-regex';
const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
const panelInfo = props.panelInfo; const panelInfo = props.panelInfo;
@ -9,7 +10,14 @@ const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
return <div>{Translate.notfound}</div>; return <div>{Translate.notfound}</div>;
} }
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 ( return (
<WebviewKeepAlive key={String(url)} className="w-full h-full" url={url} /> <WebviewKeepAlive key={String(url)} className="w-full h-full" url={url} />

@ -829,8 +829,10 @@ importers:
client/web/plugins/com.msgbyte.webview: client/web/plugins/com.msgbyte.webview:
specifiers: specifiers:
script_sanitize: ^1.2.6 script_sanitize: ^1.2.6
url-regex: ^5.0.0
dependencies: dependencies:
script_sanitize: 1.2.6 script_sanitize: 1.2.6
url-regex: 5.0.0
client/web/plugins/com.msgbyte.wenshushu: client/web/plugins/com.msgbyte.wenshushu:
specifiers: specifiers:
@ -844,6 +846,9 @@ importers:
devDependencies: devDependencies:
react: 18.2.0 react: 18.2.0
packages/types:
specifiers: {}
server: server:
specifiers: specifiers:
'@babel/helper-compilation-targets': ^7.18.2 '@babel/helper-compilation-targets': ^7.18.2

Loading…
Cancel
Save