From bfdfe5ce6a2376e5794ac3156c74f2234f48ba9f Mon Sep 17 00:00:00 2001 From: Mansehej Singh Date: Wed, 17 Apr 2024 00:08:38 +0100 Subject: [PATCH] fix: emails with single quotes not being validated (#2889) --- deno/lib/__tests__/string.test.ts | 1 + deno/lib/types.ts | 2 +- src/__tests__/string.test.ts | 1 + src/types.ts | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index f75d3abc8..21ba9ab16 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -65,6 +65,7 @@ test("email validations", () => { `work+user@mail.com`, `tom@test.te-st.com`, `something@subdomain.domain-with-hyphens.tld`, + `common'name@domain.com`, `francois@etu.inp-n7.fr`, ]; const invalidEmails = [ diff --git a/deno/lib/types.ts b/deno/lib/types.ts index bba304357..7b23e79b8 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -592,7 +592,7 @@ const nanoidRegex = /^[a-z0-9_-]{21}$/i; // const emailRegex = // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i; const emailRegex = - /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; + /^(?!\.)(?!.*\.\.)([A-Z0-9_'+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; // const emailRegex = // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i; diff --git a/src/__tests__/string.test.ts b/src/__tests__/string.test.ts index 6530b6be1..5b4e5dc4d 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -64,6 +64,7 @@ test("email validations", () => { `work+user@mail.com`, `tom@test.te-st.com`, `something@subdomain.domain-with-hyphens.tld`, + `common'name@domain.com`, `francois@etu.inp-n7.fr`, ]; const invalidEmails = [ diff --git a/src/types.ts b/src/types.ts index 98db0c8a0..60e57828b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -592,7 +592,7 @@ const nanoidRegex = /^[a-z0-9_-]{21}$/i; // const emailRegex = // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i; const emailRegex = - /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; + /^(?!\.)(?!.*\.\.)([A-Z0-9_'+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; // const emailRegex = // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;