Skip to content

Commit

Permalink
fix(isUUID) for null version argument supply
Browse files Browse the repository at this point in the history
  • Loading branch information
theteladras committed Oct 12, 2021
1 parent 13651ea commit 033b22f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/isUUID.js
Expand Up @@ -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);
}
28 changes: 28 additions & 0 deletions test/validators.js
Expand Up @@ -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],
Expand Down

0 comments on commit 033b22f

Please sign in to comment.