From 40e72f9eaf576985f876d1afc2dbc22f73abc1ba Mon Sep 17 00:00:00 2001 From: mokemoko Date: Thu, 29 Feb 2024 19:46:34 +0900 Subject: [PATCH] fix: escape hyphen in regex --- deno/lib/__tests__/string.test.ts | 2 ++ deno/lib/types.ts | 4 ++++ src/__tests__/string.test.ts | 2 ++ src/types.ts | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index 21ba9ab16..ac72d42cd 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -82,6 +82,8 @@ test("email validations", () => { `" "@example.org`, `"john..doe"@example.org`, `"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com`, + // do not support comma + `a,b@domain.com`, // do not support IPv4 `email@123.123.123.123`, diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 7b23e79b8..77533181e 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -592,7 +592,11 @@ 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 = +<<<<<<< HEAD /^(?!\.)(?!.*\.\.)([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; +>>>>>>> f5b65ff (fix: escape hyphen in regex) // 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 5b4e5dc4d..915532272 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -81,6 +81,8 @@ test("email validations", () => { `" "@example.org`, `"john..doe"@example.org`, `"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com`, + // do not support comma + `a,b@domain.com`, // do not support IPv4 `email@123.123.123.123`, diff --git a/src/types.ts b/src/types.ts index 60e57828b..33c25739d 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;