From 033b22f9e9815f170f7d9e9e4e6fde35502f6c56 Mon Sep 17 00:00:00 2001 From: Sanel Hadzini Date: Tue, 12 Oct 2021 14:38:08 +0200 Subject: [PATCH] fix(isUUID) for null version argument supply --- src/lib/isUUID.js | 4 ++-- test/validators.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib/isUUID.js b/src/lib/isUUID.js index 61d938ac3..e22193d0f 100644 --- a/src/lib/isUUID.js +++ b/src/lib/isUUID.js @@ -7,8 +7,8 @@ const uuid = { all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, }; -export default function isUUID(str, version = 'all') { +export default function isUUID(str, version) { assertString(str); - const pattern = uuid[version]; + const pattern = uuid[version ?? 'all']; return pattern && pattern.test(str); } diff --git a/test/validators.js b/test/validators.js index 91794d521..600fe444f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4413,6 +4413,34 @@ describe('Validators', () => { 'AAAAAAAA-1111-1111-AAAG-111111111111', ], }); + test({ + validator: 'isUUID', + args: [undefined], + valid: [ + 'A117FBC9-4BED-3078-CF07-9141BA07C9F3', + 'A117FBC9-4BED-5078-AF07-9141BA07C9F3', + ], + invalid: [ + '', + 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', + 'A987FBC94BED3078CF079141BA07C9F3', + 'A11AAAAA-1111-1111-AAAG-111111111111', + ], + }); + test({ + validator: 'isUUID', + args: [null], + valid: [ + 'A127FBC9-4BED-3078-CF07-9141BA07C9F3', + ], + invalid: [ + '', + 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', + 'A127FBC9-4BED-3078-CF07-9141BA07C9F3xxx', + '912859', + 'A12AAAAA-1111-1111-AAAG-111111111111', + ], + }); test({ validator: 'isUUID', args: [3],