Skip to content

Commit

Permalink
Allow address literals to bypass minDomainAtoms
Browse files Browse the repository at this point in the history
For #180.
  • Loading branch information
skeggse committed Oct 7, 2018
1 parent 32397f3 commit 3817165
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ exports.validate = internals.validate = function (email, options, callback) {
// labels 63 octets or less
updateResult(internals.diagnoses.rfc5322LabelTooLong);
}
else if (options.minDomainAtoms && atomData.domains.length < options.minDomainAtoms) {
else if (options.minDomainAtoms && atomData.domains.length < options.minDomainAtoms && (atomData.domains.length !== 1 || atomData.domains[0][0] !== '[')) {
updateResult(internals.diagnoses.errDomainTooShort);
}
else if (options.tldWhitelist || options.tldBlacklist) {
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ describe('validate()', () => {
expect(Isemail.validate(expectations[0][0])).to.equal(expectations[0][1] < internals.defaultThreshold);
});

it('should permit address literals with multiple required domain atoms', () => {

expect(Isemail.validate('joe@[IPv6:2a00:1450:4001:c02::1b]', {
minDomainAtoms: 2,
errorLevel: true
})).to.equal(diag.rfc5321AddressLiteral);

// Do not provide the same treatment to mixed domain parts.
expect(Isemail.validate('joe@[IPv6:2a00:1450:4001:c02::1b].com', {
minDomainAtoms: 3,
errorLevel: true
})).to.equal(diag.errDomainTooShort);
});

expectations.forEach((obj, i) => {

const email = obj[0];
Expand Down

0 comments on commit 3817165

Please sign in to comment.