Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support granular diagnosis exclusion #187

Merged
merged 2 commits into from
Oct 18, 2018
Merged

Conversation

skeggse
Copy link
Owner

@skeggse skeggse commented Oct 7, 2018

This adds a new excludeDiagnoses option (documentation pending) to Isemail.validate which specifies a set of diagnostic codes to exclude from validation. For example, consider the following diagnoses:

rfc5321TLD: 9,
rfc5321TLDNumeric: 10,
rfc5321QuotedString: 11,
rfc5321AddressLiteral: 12,

If you want to accept 11, and 12, but prohibit 10, you'd previously need to run isemail twice with two different errorLevels. That workaround doesn't scale well beyond a single gap, however. With the new excludeDiagnoses option, we can be more specific about what to allow through:

const options = {
    errorLevel: Isemail.diagnoses.rfc5321TLDNumeric,
    excludeDiagnoses: [
        Isemail.diagnoses.rfc5321QuotedString,
        Isemail.diagnoses.rfc5321AddressLiteral
    ]
};

Isemail.validate('joe@[127.0.0.1]', options) // => true
Isemail.validate('joe@127.0.0.1', options) // => false
Isemail.validate('"joe"@hapijs.com', options) // => true

Fixes #180. Is also an imperfect solution to #162.

@skeggse skeggse merged commit 7b685e0 into master Oct 18, 2018
@skeggse skeggse deleted the granular-diagnosis-exclusion branch October 18, 2018 16:23
@skeggse
Copy link
Owner Author

skeggse commented Oct 18, 2018

Released in 3.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant