changeset 30617:b8782b02330d

Catch some more invalid email addresses, thanks to Mark for additional tests (not that I agree with all of them)
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 15 Jun 2010 01:28:17 +0000
parents 72d9caae4406
children bb835d43f29f
files libpurple/tests/test_util.c libpurple/util.c
diffstat 2 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/tests/test_util.c	Mon Jun 14 22:23:33 2010 +0000
+++ b/libpurple/tests/test_util.c	Tue Jun 15 01:28:17 2010 +0000
@@ -109,13 +109,13 @@
 	"colonButNoPort@127.0.0.1:",
 	""
 	/* "someone-else@127.0.0.1.26", */
-	/* ".localStartsWithDot@domain.com", */
-	/* "localEndsWithDot.@domain.com", */
-	/* "two..consecutiveDots@domain.com", */
-	/* "domainStartsWithDash@-domain.com", */
+	".localStartsWithDot@domain.com",
+	/* "localEndsWithDot.@domain.com", */ /* I don't think this is invalid -- Stu */
+	/* "two..consecutiveDots@domain.com", */ /* I don't think this is invalid -- Stu */
+	"domainStartsWithDash@-domain.com",
 	"domainEndsWithDash@domain-.com",
 	/* "numbersInTLD@domain.c0m", */
-	/* "missingTLD@domain.", */
+	/* "missingTLD@domain.", */ /* This certainly isn't invalid -- Stu */
 	"! \"#$%(),/;<>[]`|@invalidCharsInLocal.org",
 	"invalidCharsInDomain@! \"#$%(),/;<>_[]`|.org",
 	/* "local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org" */
--- a/libpurple/util.c	Mon Jun 14 22:23:33 2010 +0000
+++ b/libpurple/util.c	Tue Jun 15 01:28:17 2010 +0000
@@ -4271,6 +4271,8 @@
 
 	g_return_val_if_fail(address != NULL, FALSE);
 
+	if (*address == '.') return FALSE;
+
 	/* first we validate the name portion (name@domain) (rfc822)*/
 	for (c = address;  *c;  c++) {
 		if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) == '\"')) {
@@ -4304,7 +4306,7 @@
 	do {
 		if (*c == '.' && (c == domain || *(c - 1) == '.' || *(c - 1) == '-'))
 			return FALSE;
-		if (*c == '-' && *(c - 1) == '.') return FALSE;
+		if (*c == '-' && (*(c - 1) == '.' || *(c - 1) == '@')) return FALSE;
 		if ((*c < '0' && *c != '-' && *c != '.') || (*c > '9' && *c < 'A') ||
 			(*c > 'Z' && *c < 'a') || (*c > 'z')) return FALSE;
 	} while (*++c);