Skip to content

Commit

Permalink
fix(isUUID): fix for null version argument supply (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
theteladras authored and profnandaa committed Oct 31, 2021
1 parent 256de2a commit 594ce01
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[![undefined, null].includes(version) ? version : 'all'];
return pattern && pattern.test(str);
}
28 changes: 28 additions & 0 deletions test/validators.js
Expand Up @@ -4450,6 +4450,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 594ce01

Please sign in to comment.