Skip to content

Commit

Permalink
Fix for tlivings#73: Empty string ignores regex string validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yosheeck committed Dec 19, 2019
1 parent c3ac49c commit f90df37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ class SchemaResolver {

if (Util.isUndefined(schema.minLength)) {
schema.minLength = 0;
}

if (schema.minLength === 0) {
} else if (schema.minLength === 0) {
joischema = joischema.allow('');
}
Util.isNumber(schema.minLength) && (joischema = joischema.min(schema.minLength));
Expand Down
8 changes: 6 additions & 2 deletions test/test-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Test('types', function (t) {
});

t.test('string regex', function (t) {
t.plan(2);
t.plan(3);

const schema = Enjoi.schema({
'type': 'string',
Expand All @@ -284,11 +284,15 @@ Test('types', function (t) {
t.ok(error, 'error.');
});

Joi.validate('', schema, function (error, value) {
t.ok(error, 'error.');
});

Joi.validate('foobar', schema, function (error, value) {
t.ok(!error, 'no error.');
});
});

t.test('string length', function (t) {
t.plan(3);

Expand Down

0 comments on commit f90df37

Please sign in to comment.