Skip to content

Commit

Permalink
fix: isHttpUrl utils
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklin committed Jul 2, 2024
1 parent ada87b2 commit 343b4d3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/web/utils/src/typeChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ export const isServerRendering = (() => {
// Define a function isHttpUrl that takes a string argument path and returns true if it is a valid Http URL.
// 定义一个函数 isHttpUrl,它接受一个字符串参数 path,如果它是有效的Http URL,则返回 true。
export function isHttpUrl(path: string): boolean {
const regex = /^https?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/i;
return regex.test(path);
try {
const url = new URL(path);
return url.protocol === "http:" || url.protocol === "https:";
} catch (error) {
return false;
}
}

export function isComponentInstance(value: any): value is ComponentPublicInstance {
Expand Down

0 comments on commit 343b4d3

Please sign in to comment.