From: Jérôme Benoit Date: Tue, 25 Oct 2022 23:27:39 +0000 (+0200) Subject: Fix UUID validation regexp X-Git-Tag: v1.1.86~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8bd02502e5cb44f91964241a5bc93b762ca7557e;p=e-mobility-charging-stations-simulator.git Fix UUID validation regexp Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 719200fa..bc957c24 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -16,7 +16,9 @@ export default class Utils { } public static validateUUID(uuid: string): boolean { - return /\/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$\/i/.test(uuid); + return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test( + uuid + ); } public static async sleep(milliSeconds: number): Promise { diff --git a/test/utils/UtilsTest.ts b/test/utils/UtilsTest.ts index c431642e..9e882cc5 100644 --- a/test/utils/UtilsTest.ts +++ b/test/utils/UtilsTest.ts @@ -3,6 +3,12 @@ import expect from 'expect'; import Utils from '../../src/utils/Utils'; describe('Utils test suite', () => { + it('Verify generateUUID()/validateUUID()', () => { + const uuid = Utils.generateUUID(); + expect(uuid.length).toEqual(36); + expect(Utils.validateUUID(uuid)).toBe(true); + }); + it('Verify secureRandom()', () => { const random = Utils.secureRandom(); expect(typeof random === 'number').toBe(true);