Fix Punycode domain validation

This commit is contained in:
Shubham Singh
2026-07-19 13:45:33 +05:30
parent c30fe5b574
commit 0275f44056
2 changed files with 22 additions and 2 deletions
+3 -2
View File
@@ -171,9 +171,10 @@ export function isValidDomain(domain: string): boolean {
if (!/^[a-zA-Z0-9-]+$/.test(label)) return false;
}
// TLD should be at least 2 characters and contain only letters
// TLD should be at least 2 characters. Punycode TLDs can contain digits
// and hyphens, so validity is ultimately enforced by the TLD allowlist.
const tld = labels[labels.length - 1];
if (tld.length < 2 || !/^[a-zA-Z]+$/.test(tld)) return false;
if (tld.length < 2) return false;
// Check if TLD is in the list of valid TLDs
if (!validTlds.includes(tld.toUpperCase())) return false;