Skip to content

Commit 07cd995

Browse files
committed
fix(isUUID) for null version argument supply
1 parent 29a5d37 commit 07cd995

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/lib/isUUID.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const uuid = {
99
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
1010
};
1111

12-
export default function isUUID(str, version = 'all') {
12+
export default function isUUID(str, version) {
1313
assertString(str);
14-
const pattern = uuid[version];
14+
const pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
1515
return !!pattern && pattern.test(str);
1616
}

test/validators.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,34 @@ describe('Validators', () => {
44134413
'AAAAAAAA-1111-1111-AAAG-111111111111',
44144414
],
44154415
});
4416+
test({
4417+
validator: 'isUUID',
4418+
args: [undefined],
4419+
valid: [
4420+
'A117FBC9-4BED-3078-CF07-9141BA07C9F3',
4421+
'A117FBC9-4BED-5078-AF07-9141BA07C9F3',
4422+
],
4423+
invalid: [
4424+
'',
4425+
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
4426+
'A987FBC94BED3078CF079141BA07C9F3',
4427+
'A11AAAAA-1111-1111-AAAG-111111111111',
4428+
],
4429+
});
4430+
test({
4431+
validator: 'isUUID',
4432+
args: [null],
4433+
valid: [
4434+
'A127FBC9-4BED-3078-CF07-9141BA07C9F3',
4435+
],
4436+
invalid: [
4437+
'',
4438+
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
4439+
'A127FBC9-4BED-3078-CF07-9141BA07C9F3xxx',
4440+
'912859',
4441+
'A12AAAAA-1111-1111-AAAG-111111111111',
4442+
],
4443+
});
44164444
test({
44174445
validator: 'isUUID',
44184446
args: [1],

0 commit comments

Comments
 (0)