Skip to content

Commit be65d7d

Browse files
committed
fix: allow url without tld to match regex path
1 parent de578ec commit be65d7d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function urlPath(path: string): string {
22
path = path.trim();
33

44
//regex to check if is an absolute url (with *a* protocol) or a valid URI
5-
const urlRegex = /^([a-z0-9]+:\/\/|www.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i;
5+
const urlRegex = /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*|localhost)(:\d{1,5})?(\/[^\s]*)?$/i
66

77
if (path.match(urlRegex)) {
88
return path;

0 commit comments

Comments
 (0)