Fix URL validation on long/internationalized URLs (#1423)

* Add URL validation tests

Add test for longer TLDs
Add test for internationalized TLDs

* Fix URL validation with long TLDs

* TLD max size match RFC 1034

---------

Co-authored-by: Jérémy M <jeremy.magrin@gmail.com>
This commit is contained in:
Ragnar Laud
2023-09-04 12:30:43 +03:00
committed by GitHub
parent a46210bb80
commit c998c039ec
2 changed files with 16 additions and 1 deletions

View File

@ -4,7 +4,7 @@ export function isURL(url: string | undefined | null) {
return (
isDefined(url) &&
url.match(
/^(https?:\/\/)?(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i,
/^(https?:\/\/)?(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i,
)
);
}