Skip to content

Commit 3f3acc3

Browse files
committed
fix: profile url check
1 parent e5aab07 commit 3f3acc3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/util/format.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ export function formatDate(date: Date): string {
5252
}
5353

5454
// 校验是否 url 格式
55-
export function isHttpOrHttps(url: any) {
56-
const regex = /^(https?):\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/;
57-
return regex.test(url);
55+
export function isHttpOrHttps(url: string): boolean {
56+
if (url.trim() === '') return false;
57+
try {
58+
const parsed = new URL(url);
59+
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
60+
} catch {
61+
return false;
62+
}
5863
}
5964

6065
const innerTemplate = ['m0', 'm1', 'm2', 'm3']

0 commit comments

Comments
 (0)