Skip to content

Commit 1c84bc2

Browse files
committed
fix(isUUID) for null version argument supply
1 parent 13651ea commit 1c84bc2

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/lib/isUUID.js

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

10-
export default function isUUID(str, version = 'all') {
10+
export default function isUUID(str, version) {
1111
assertString(str);
12-
const pattern = uuid[version];
12+
const pattern = uuid[version || 'all'];
1313
return pattern && pattern.test(str);
1414
}

test/validators.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,47 @@ 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+
});
4444+
test({
4445+
validator: 'isUUID',
4446+
args: [0],
4447+
valid: [
4448+
'A137FBC9-4BED-3078-CF07-9141BA07C9F3',
4449+
],
4450+
invalid: [
4451+
'',
4452+
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
4453+
'A137FBC9-4BED-3078-CF07-9141BA07C9F3xxx',
4454+
'A13AAAAA-1111-1111-AAAG-111111111111',
4455+
],
4456+
});
44164457
test({
44174458
validator: 'isUUID',
44184459
args: [3],

0 commit comments

Comments
 (0)