fix: Allow single-label domains and missing dots (#25899)
This commit is contained in:
1 parent
b83f8dd6b8
commit
db2caa17ce
2 files changed
+6
-5
No files matched your search
@@ -55,13 +55,14 @@ describe("excludeOrRequireEmailSchema", () => {
|
|||||||
it("accepts long multi-level domains", () => {
|
it("accepts long multi-level domains", () => {
|
||||||
expect(parse("example.co.uk.test.com").success).toBe(true);
|
expect(parse("example.co.uk.test.com").success).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("accepts single-label domains and missing dots", () => {
|
||||||
|
expect(parse("example").success).toBe(true);
|
||||||
|
expect(parse("@example").success).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("invalid inputs", () => {
|
describe("invalid inputs", () => {
|
||||||
it("rejects single-label domains and missing dots", () => {
|
|
||||||
expect(parse("example").success).toBe(false);
|
|
||||||
expect(parse("@example").success).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects invalid TLD lengths", () => {
|
it("rejects invalid TLD lengths", () => {
|
||||||
expect(parse("example.c").success).toBe(false);
|
expect(parse("example.c").success).toBe(false);
|
||||||
|
|||||||
@@ -970,7 +970,7 @@ export const excludeOrRequireEmailSchema = z.string().superRefine((val, ctx) =>
|
|||||||
// Accept forms: domain-only, `@domain`, or `local@domain`
|
// Accept forms: domain-only, `@domain`, or `local@domain`
|
||||||
// - Domain labels: alnum, hyphens allowed internally, no leading/trailing hyphen
|
// - Domain labels: alnum, hyphens allowed internally, no leading/trailing hyphen
|
||||||
// - Require at least one dot and end with an alpha TLD of length ≥2
|
// - Require at least one dot and end with an alpha TLD of length ≥2
|
||||||
const EMAIL_OR_DOMAIN_PATTERN = /^(?:[a-z0-9._+'-]+@|@)?(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;
|
const EMAIL_OR_DOMAIN_PATTERN = /^(?:[a-z0-9._+'-]+@|@)?(?:[a-z]{2,}|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,})$/i;
|
||||||
|
|
||||||
const isValid = allDomains.every((entry) => EMAIL_OR_DOMAIN_PATTERN.test(entry));
|
const isValid = allDomains.every((entry) => EMAIL_OR_DOMAIN_PATTERN.test(entry));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user