From 5ec98e1c4420957f93a7388bf49fb01d91bcbcd0 Mon Sep 17 00:00:00 2001 From: Luca De Santis <96928386+fvckDesa@users.noreply.github.com> Date: Sun, 26 Feb 2023 22:08:44 +0100 Subject: [PATCH] Fix email issues in pull request #1982 (#2058) * Invalidate emails with '.' next to another * More validation in IPv4 domain In a valid IPv4 the numbers must go from 0 to 255 * Add IPv6 domain in email validation * Save selected theme in localStorage --- deno/lib/__tests__/string.test.ts | 19 +++++++++++++++++++ deno/lib/types.ts | 15 +++++++-------- index.html | 21 +++++++++++++-------- src/__tests__/string.test.ts | 19 +++++++++++++++++++ src/types.ts | 15 +++++++-------- 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index 3df55f7b2..b3996bec8 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -71,6 +71,14 @@ test("more email validations", () => { `user@[68.185.127.196]`, `ipv4@[85.129.96.247]`, `valid@[79.208.229.53]`, + `valid@[255.255.255.255]`, + `valid@[255.0.55.2]`, + `valid@[255.0.55.2]`, + `hgrebert0@[IPv6:4dc8:ac7:ce79:8878:1290:6098:5c50:1f25]`, + `bshapiro4@[IPv6:3669:c709:e981:4884:59a3:75d1:166b:9ae]`, + `jsmith@[IPv6:2001:db8::1]`, + `postmaster@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]`, + `postmaster@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:192.168.1.1]`, ]; const invalidEmails = [ `Abc.example.com`, @@ -88,6 +96,17 @@ test("more email validations", () => { `invalid@[68.185.127.196.55]`, `temp@[192.168.1]`, `temp@[9.18.122.]`, + `double..point@test.com`, + `asdad@test..com`, + `asdad@hghg...sd...au`, + `asdad@hghg........au`, + `invalid@[256.2.2.48]`, + `invalid@[256.2.2.48]`, + `invalid@[999.465.265.1]`, + `jkibbey4@[IPv6:82c4:19a8::70a9:2aac:557::ea69:d985:28d]`, + `mlivesay3@[9952:143f:b4df:2179:49a1:5e82:b92e:6b6]`, + `gbacher0@[IPv6:bc37:4d3f:5048:2e26:37cc:248e:df8e:2f7f:af]`, + `invalid@[IPv6:5348:4ed3:5d38:67fb:e9b:acd2:c13:192.168.256.1]`, ]; const emailSchema = z.string().email(); expect( diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 364911222..15f5b0bb2 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -525,8 +525,7 @@ const uuidRegex = // eslint-disable-next-line const emailRegex = - /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|([^-]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}))$/; - + /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/; // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression const emojiRegex = @@ -3502,7 +3501,7 @@ export class ZodFunction< return this._def.returns; } - args[0]>( + args[0]>( ...items: Items ): ZodFunction, Returns> { return new ZodFunction({ @@ -4620,18 +4619,18 @@ const oboolean = () => booleanType().optional(); export const coerce = { string: ((arg) => - ZodString.create({ ...arg, coerce: true })) as typeof ZodString["create"], + ZodString.create({ ...arg, coerce: true })) as (typeof ZodString)["create"], number: ((arg) => - ZodNumber.create({ ...arg, coerce: true })) as typeof ZodNumber["create"], + ZodNumber.create({ ...arg, coerce: true })) as (typeof ZodNumber)["create"], boolean: ((arg) => ZodBoolean.create({ ...arg, coerce: true, - })) as typeof ZodBoolean["create"], + })) as (typeof ZodBoolean)["create"], bigint: ((arg) => - ZodBigInt.create({ ...arg, coerce: true })) as typeof ZodBigInt["create"], + ZodBigInt.create({ ...arg, coerce: true })) as (typeof ZodBigInt)["create"], date: ((arg) => - ZodDate.create({ ...arg, coerce: true })) as typeof ZodDate["create"], + ZodDate.create({ ...arg, coerce: true })) as (typeof ZodDate)["create"], }; export { diff --git a/index.html b/index.html index 358a82a58..daae856cd 100644 --- a/index.html +++ b/index.html @@ -206,22 +206,27 @@
-