From 240488f5d35a24567181c3dfbc5c0aa46bc3fe53 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Thu, 15 Aug 2024 21:10:02 +0400 Subject: [PATCH] Update uuid and email regexes --- packages/tests/src/core/S_String_uuid_test.res | 10 ++++++++++ src/S_Core.bs.mjs | 4 ++-- src/S_Core.res | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/tests/src/core/S_String_uuid_test.res b/packages/tests/src/core/S_String_uuid_test.res index 82c0dbfe..0782bb2d 100644 --- a/packages/tests/src/core/S_String_uuid_test.res +++ b/packages/tests/src/core/S_String_uuid_test.res @@ -10,6 +10,16 @@ test("Successfully parses valid data", t => { ) }) +test("Successfully parses uuid V7", t => { + let schema = S.string->S.uuid + + t->Assert.deepEqual( + "019122ba-bb79-75ef-9a97-190f1effbb54"->S.parseAnyWith(schema), + Ok("019122ba-bb79-75ef-9a97-190f1effbb54"), + (), + ) +}) + test("Fails to parse invalid data", t => { let schema = S.string->S.uuid diff --git a/src/S_Core.bs.mjs b/src/S_Core.bs.mjs index 5ad070f3..95ee29e4 100644 --- a/src/S_Core.bs.mjs +++ b/src/S_Core.bs.mjs @@ -1697,9 +1697,9 @@ function refinements(schema) { var cuidRegex = /^c[^\s-]{8,}$/i; -var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i; +var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i; -var emailRegex = /^(([^<>()[\]\\.,;:\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,})+))$/; +var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; var datetimeRe = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/; diff --git a/src/S_Core.res b/src/S_Core.res index 51220213..868122a4 100644 --- a/src/S_Core.res +++ b/src/S_Core.res @@ -2463,9 +2463,9 @@ module String = { } let cuidRegex = %re(`/^c[^\s-]{8,}$/i`) - let uuidRegex = %re(`/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i`) + let uuidRegex = %re(`/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i`) // Adapted from https://stackoverflow.com/a/46181/1550155 - let emailRegex = %re(`/^(([^<>()[\]\\.,;:\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,})+))$/`) + let emailRegex = %re(`/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i`) // Adapted from https://stackoverflow.com/a/3143231 let datetimeRe = %re(`/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/`)