Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ module.exports = Any.extend({
email: {
method(options = {}) {

Common.assertOptions(options, ['allowFullyQualified', 'allowUnicode', 'ignoreLength', 'maxDomainSegments', 'minDomainSegments', 'multiple', 'separator', 'tlds']);
Common.assertOptions(options, ['allowFullyQualified', 'allowUnicode', 'allowUnderscore', 'ignoreLength', 'maxDomainSegments', 'minDomainSegments', 'multiple', 'separator', 'tlds']);
assert(options.multiple === undefined || typeof options.multiple === 'boolean', 'multiple option must be an boolean');

const address = internals.addressOptions(options);
Expand Down
28 changes: 28 additions & 0 deletions test/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,34 @@ describe('string', () => {
expect(() => Joi.string().email({ multiple: false })).to.not.throw();
expect(() => Joi.string().email({ multiple: {} })).to.throw('multiple option must be an boolean');
expect(() => Joi.string().email({ multiple: 'abc' })).to.throw('multiple option must be an boolean');

expect(() => Joi.string().email({ allowUnderscore: true })).to.not.throw();
expect(() => Joi.string().email({ allowUnderscore: false })).to.not.throw();
});

it('validates email with underscores in domain', () => {

const validSchema = Joi.string().email({ allowUnderscore: true });
Helper.validate(validSchema, [
['user@_acme-challenge.example.com', true],
['user@_abc.example.com', true]
]);

const invalidSchema = Joi.string().email();
Helper.validate(invalidSchema, [
['user@_acme-challenge.example.com', false, {
message: '"value" must be a valid email',
path: [],
type: 'string.email',
context: { value: 'user@_acme-challenge.example.com', invalids: ['user@_acme-challenge.example.com'], label: 'value' }
}],
['user@_abc.example.com', false, {
message: '"value" must be a valid email',
path: [],
type: 'string.email',
context: { value: 'user@_abc.example.com', invalids: ['user@_abc.example.com'], label: 'value' }
}]
]);
});

it('validates email', () => {
Expand Down