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

validateEmail incorrectly tests results of std.net.isemail.isEmail() #1580

Closed
radcapricorn opened this Issue Oct 1, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@radcapricorn
Contributor

radcapricorn commented Oct 1, 2016

vibe.utils.validation.validateEmail tests the results of std.net.isemail.isEmail like this:

return isEmail(str) != EmailStatusCode.valid;

However, isEmail returns EmailStatus, not EmailStatusCode. Incidentally, EmailStatus aliases self to a bool property valid(), which allows the code above to compile. But the logic is reversed, since EmailStatusCode.valid == 0, although isEmail(str) == false when the e-mail is invalid.
Paired with Phobos fixes between versions, this leads to further inconsistencies at run time.
For example, with dmd 2.071.1 (when there was an issue in Phobos):

auto result = isEmail("a@b.c");
/*
result == EmailStatus
{
    valid: false
    localPart: a
    domainPart: b.c
    statusCode: error
}
*/
auto err = appender!string();
auto vibeResult = validateEmail(err, "a@b.c");
/*
vibeResult == true
*/

Even though isEmail() (incorrectly) returned an invalid status, vibe treats it as valid.
And with current dmd nightly:

auto result = isEmail("a@b.c");
/*
result == EmailStatus
{
    valid: true
    localPart: a
    domainPart: b.c
    statusCode: valid
}
*/
auto err = appender!string();
auto vibeResult = validateEmail(err, "a@b.c");
/*
vibeResult == false
err.data == "The email address is invalid."
*/

Vice-versa, isEmail() now correctly returns a valid status, but vibe treats it as invalid.

@radcapricorn

This comment has been minimized.

Show comment
Hide comment
@radcapricorn

radcapricorn Oct 1, 2016

Contributor

Note: Phobos issue mentioned above holds for Phobos included with dmd 2.071.2 as well. The proposed fix would effectively break validateEmail() for anyone not using nightly dmd/Phobos builds.

Contributor

radcapricorn commented Oct 1, 2016

Note: Phobos issue mentioned above holds for Phobos included with dmd 2.071.2 as well. The proposed fix would effectively break validateEmail() for anyone not using nightly dmd/Phobos builds.

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Oct 14, 2016

Member

Fixed by #1582.

Member

s-ludwig commented Oct 14, 2016

Fixed by #1582.

@s-ludwig s-ludwig closed this Oct 14, 2016

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