Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #188 from hapijs/literals-bypass-min-atoms
Browse files Browse the repository at this point in the history
Allow address literals to bypass minDomainAtoms
  • Loading branch information
skeggse authored Oct 18, 2018
2 parents 72313d0 + 3817165 commit 6b4caf9
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 @@ -1390,7 +1390,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 @@ -199,6 +199,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 6b4caf9

Please sign in to comment.