From 71f7b36684052810a7a10c6210c945ce6975a2eb Mon Sep 17 00:00:00 2001 From: Gianmarco Manni Date: Fri, 6 Jun 2025 12:37:37 +0200 Subject: [PATCH 1/3] x --- .gitignore | 65 +++++++++++++++++++++++--------------------- CHANGELOG.md | 4 +++ src/lib/guid.spec.ts | 4 +-- src/lib/guid.ts | 6 ++-- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index dbacc54..e26c031 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,35 @@ -# See https://help.github.com/ignore-files/ for more about ignoring files. - -# dependencies -node_modules - -# builds -build -dist -.rpt2_cache - -# misc -.DS_Store -.env -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Optional eslint cache -.eslintcache - -coverage - -storybook-static -.terraform -terraform - +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +node_modules + +# builds +build +dist +.rpt2_cache + +# misc +.DS_Store +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Optional eslint cache +.eslintcache + +coverage + +storybook-static +.terraform +terraform + +# Ignore vs folder +.vs + .npmrc \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 53cd1a5..5986aae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `isValidGuid` unwanted behaviour which was returning false for Guid sequentially generated by following Microsoft EntityFramework + ## [1.3.0] - 2025-04-10 ### Changed diff --git a/src/lib/guid.spec.ts b/src/lib/guid.spec.ts index d6a48b1..0c7dd9b 100644 --- a/src/lib/guid.spec.ts +++ b/src/lib/guid.spec.ts @@ -19,11 +19,11 @@ describe("guid tests", () => { [" ", false], ["507956c7-30b3-4401-9800-e5e7f8f3276X", false], ["507956c7-30b3-4401-9800-e5e7f8f32761", true], + ["f094d99a-347e-4fe5-eea2-08dbc5deb2a0", true], [newGuid(), true], [emptyGuid, true], ["3B467B14-CD99-4199-8E35-82B3C37182BA", true], - // MAX not recognized as guid > https://github.com/uuidjs/uuid/pull/714 - ["ffffffff-ffff-ffff-ffff-ffffffffffff", false], + ["ffffffff-ffff-ffff-ffff-ffffffffffff", true], ])("isValidGuid", (value, expected) => { expect(isValidGuid(value)).toBe(expected); }); diff --git a/src/lib/guid.ts b/src/lib/guid.ts index 630e350..538052e 100644 --- a/src/lib/guid.ts +++ b/src/lib/guid.ts @@ -9,12 +9,14 @@ export function newGuid() { } /** - * Check whether a string it is a valid Guid (version 4 UUID) + * Check whether a string it is a valid Guid * @param str The string to test whether it is a valid Guid * @returns A value indicating whether the string is a valid Guid */ export function isValidGuid(str: string) { - return uuid.validate(str); + const regex = + /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[0-9a-f][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i; + return typeof str === "string" && regex.test(str); } /** From 36867b08b6f660769dfc8e3867408dbde5cbbdc9 Mon Sep 17 00:00:00 2001 From: Gianmarco Manni Date: Fri, 6 Jun 2025 12:48:28 +0200 Subject: [PATCH 2/3] x --- src/lib/guid.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/guid.ts b/src/lib/guid.ts index 538052e..0577f1f 100644 --- a/src/lib/guid.ts +++ b/src/lib/guid.ts @@ -14,8 +14,7 @@ export function newGuid() { * @returns A value indicating whether the string is a valid Guid */ export function isValidGuid(str: string) { - const regex = - /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[0-9a-f][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i; + const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; return typeof str === "string" && regex.test(str); } From 693ad21cc90a8838a458eaf86502f7cc4f146778 Mon Sep 17 00:00:00 2001 From: Gianmarco Manni Date: Fri, 6 Jun 2025 12:49:45 +0200 Subject: [PATCH 3/3] x --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5986aae..99dc9ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `isValidGuid` unwanted behaviour which was returning false for Guid sequentially generated by following Microsoft EntityFramework +- maxGuid (`ffffffff-ffff-ffff-ffff-ffffffffffff`) is now recognized as valid Guid ## [1.3.0] - 2025-04-10