BUG 2354: fix email validation.

https://bugs.eressea.de/view.php?id=2354
This commit is contained in:
Enno Rehling 2017-08-06 21:03:51 +02:00
parent 78f8ec0173
commit faf0f48a70
2 changed files with 9 additions and 3 deletions

View File

@ -232,8 +232,8 @@ static void test_set_email(CuTest *tc) {
CuAssertIntEquals(tc, 0, set_email(&email, "bugs@eressea.de"));
CuAssertStrEquals(tc, "bugs@eressea.de", email);
CuAssertIntEquals(tc, -1, set_email(&email, "bad@@eressea.de"));
CuAssertStrEquals(tc, "bugs@eressea.de", email);
CuAssertIntEquals(tc, -1, set_email(&email, "eressea.de"));
CuAssertIntEquals(tc, -1, set_email(&email, "eressea@"));
CuAssertStrEquals(tc, "bugs@eressea.de", email);
free(email);
test_cleanup();

View File

@ -82,12 +82,18 @@ static int spc_email_isvalid(const char *address)
if (strchr(rfc822_specials, *c))
return 0;
}
if (*c!='@') {
/* no @ symbol */
return -1;
}
domain = ++c;
if (!*c) {
return -1;
}
if (c == address || *(c - 1) == '.')
return 0;
/* next we validate the domain portion (name@domain) */
if (!*(domain = ++c))
return 0;
do {
if (*c == '.') {
if (c == domain || *(c - 1) == '.')