Skip to content

Commit 9347d6d

Browse files
authored
fix(isUUID): fix for null version argument supply (validatorjs#1777)
1 parent 29ed3a0 commit 9347d6d

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
@@ -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[![undefined, null].includes(version) ? version : 'all'];
1313
return pattern && pattern.test(str);
1414
}

test/validators.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,6 +4450,34 @@ describe('Validators', () => {
44504450
'AAAAAAAA-1111-1111-AAAG-111111111111',
44514451
],
44524452
});
4453+
test({
4454+
validator: 'isUUID',
4455+
args: [undefined],
4456+
valid: [
4457+
'A117FBC9-4BED-3078-CF07-9141BA07C9F3',
4458+
'A117FBC9-4BED-5078-AF07-9141BA07C9F3',
4459+
],
4460+
invalid: [
4461+
'',
4462+
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
4463+
'A987FBC94BED3078CF079141BA07C9F3',
4464+
'A11AAAAA-1111-1111-AAAG-111111111111',
4465+
],
4466+
});
4467+
test({
4468+
validator: 'isUUID',
4469+
args: [null],
4470+
valid: [
4471+
'A127FBC9-4BED-3078-CF07-9141BA07C9F3',
4472+
],
4473+
invalid: [
4474+
'',
4475+
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
4476+
'A127FBC9-4BED-3078-CF07-9141BA07C9F3xxx',
4477+
'912859',
4478+
'A12AAAAA-1111-1111-AAAG-111111111111',
4479+
],
4480+
});
44534481
test({
44544482
validator: 'isUUID',
44554483
args: [3],

0 commit comments

Comments
 (0)