Bug 627657 - Allow email's with no dot in the domain name for <input type='email'>. r=smaug a=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Sat, 22 Jan 2011 00:08:42 +0100
changeset 61120 d341b2ece4e43d655c9a57f80cda919d85321996
parent 61119 3f36d14effd1dc1baf2b4c8f731793424db2de35
child 61124 dd398fdba56f162be8976a21b40eb4b8b22924f9
push idunknown
push userunknown
push dateunknown
reviewerssmaug, sicking
bugs627657
milestone2.0b10pre
Bug 627657 - Allow email's with no dot in the domain name for <input type='email'>. r=smaug a=sicking
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/test/test_bug555559.html
content/html/content/test/test_bug558788-1.html
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -4112,38 +4112,33 @@ nsHTMLInputElement::IsValidEmailAddress(
     return PR_FALSE;
   }
 
   // The domain name can't begin with a dot.
   if (aValue[i] == '.') {
     return PR_FALSE;
   }
 
-  // The domain name must have at least one dot which can't follow another dot,
-  // can't be the first nor the last domain name character.
-  PRBool dotFound = PR_FALSE;
-
   // Parsing the domain name.
   for (; i < length; ++i) {
     PRUnichar c = aValue[i];
 
     if (c == '.') {
-      dotFound = PR_TRUE;
       // A dot can't follow a dot.
       if (aValue[i-1] == '.') {
         return PR_FALSE;
       }
     } else if (!(nsCRT::IsAsciiAlpha(c) || nsCRT::IsAsciiDigit(c) ||
                  c == '-')) {
       // The domain characters have to be in this list to be valid.
       return PR_FALSE;
     }
   }
 
-  return dotFound;
+  return PR_TRUE;
 }
 
 //static
 PRBool
 nsHTMLInputElement::IsPatternMatching(nsAString& aValue, nsAString& aPattern,
                                       nsIDocument* aDocument)
 {
   NS_ASSERTION(aDocument, "aDocument should be a valid pointer (not null)");
--- a/content/html/content/test/test_bug555559.html
+++ b/content/html/content/test/test_bug555559.html
@@ -36,31 +36,31 @@ function invalidEventHandler(e)
   is(e.type, "invalid", "Invalid event type should be invalid");
   gInvalid = true;
 }
 
 function checkValidEmailAddress(element)
 {
   gInvalid = false;
   ok(!element.validity.typeMismatch,
-     "Element should not suffer from type mismatch");
+     "Element should not suffer from type mismatch (with value='"+element.value+"')");
   ok(element.validity.valid, "Element should be valid");
   ok(element.checkValidity(), "Element should be valid");
   ok(!gInvalid, "The invalid event should not have been thrown");
   is(element.validationMessage, '',
      "Validation message should be the empty string");
   is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
      "rgb(0, 255, 0)", ":valid pseudo-class should apply");
 }
 
 function checkInvalidEmailAddress(element)
 {
   gInvalid = false;
   ok(element.validity.typeMismatch,
-     "Element should suffer from type mismatch");
+     "Element should suffer from type mismatch (with value='"+element.value+"')");
   ok(!element.validity.valid, "Element should not be valid");
   ok(!element.checkValidity(), "Element should not be valid");
   ok(gInvalid, "The invalid event should have been thrown");
   is(element.validationMessage, "Please enter an email address.",
      "Validation message is not valid");
   is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
      "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
 }
@@ -116,20 +116,20 @@ var illegalCharacters = "()<>[]:;@\, \t"
 for each (c in illegalCharacters)
 {
   email.value = c + '@bar.com';
   checkInvalidEmailAddress(email);
 }
 
 // Some checks on the domain part of the address.
 email.value = 'foo@bar';
-checkInvalidEmailAddress(email);
+checkValidEmailAddress(email);
 
 email.value = 'foo@b';
-checkInvalidEmailAddress(email);
+checkValidEmailAddress(email);
 
 email.value = 'foo@';
 checkInvalidEmailAddress(email);
 
 email.value = 'foo@bar.';
 checkInvalidEmailAddress(email);
 
 email.value = 'foo@foo.bar';
@@ -222,17 +222,17 @@ checkInvalidEmailAddress(email);
 
 email.value = 'foo@bar.com;foo@bar.com';
 checkInvalidEmailAddress(email);
 
 email.value = '<foo@bar.com>, <foo@bar.com>';
 checkInvalidEmailAddress(email);
 
 email.value = 'foo@bar, foo@bar.com';
-checkInvalidEmailAddress(email);
+checkValidEmailAddress(email);
 
 email.value = 'foo@bar.com, foo';
 checkInvalidEmailAddress(email);
 
 email.value = 'foo, foo@bar.com';
 checkInvalidEmailAddress(email);
 
 </script>
--- a/content/html/content/test/test_bug558788-1.html
+++ b/content/html/content/test/test_bug558788-1.html
@@ -122,17 +122,22 @@ function checkInputEmail()
   synthesizeKey("a", {});
   checkInvalidApplies(element);
 
   sendString("@b.c", element);
   checkValidApplies(element);
 
   synthesizeKey("VK_BACK_SPACE", {});
   for (var i=0; i<4; ++i) {
-    checkInvalidApplies(element);
+    if (i == 1) {
+      // a@b is a valid value.
+      checkValidApplies(element);
+    } else {
+      checkInvalidApplies(element);
+    }
     synthesizeKey("VK_BACK_SPACE", {});
   }
   checkValidApplies(element);
 
   gContent.removeChild(element);
 }
 
 function checkInputURL()