Bug 657702 - Remove leading and trailing whitespaces in <input type='email'> value sanitizing algorithm. r=smaug
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 22 Aug 2011 14:58:01 +0200
changeset 75653 c11ae0f171a4044f4ae3190148dab38267c78013
parent 75652 4b1410af17c7ff2bc900a5bd035256034eeda4bf
child 75654 ac57320746e8e9ec9dd3091740f84899d1d688b2
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerssmaug
bugs657702
milestone9.0a1
Bug 657702 - Remove leading and trailing whitespaces in <input type='email'> value sanitizing algorithm. r=smaug
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/test/forms/test_input_email.html
content/html/content/test/test_bug549475.html
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -2505,22 +2505,22 @@ nsHTMLInputElement::SanitizeValue(nsAStr
   NS_ASSERTION(!GET_BOOLBIT(mBitField, BF_PARSER_CREATING),
                "The element parsing should be finished!");
 
   switch (mType) {
     case NS_FORM_INPUT_TEXT:
     case NS_FORM_INPUT_SEARCH:
     case NS_FORM_INPUT_TEL:
     case NS_FORM_INPUT_PASSWORD:
-    case NS_FORM_INPUT_EMAIL:
       {
         PRUnichar crlf[] = { PRUnichar('\r'), PRUnichar('\n'), 0 };
         aValue.StripChars(crlf);
       }
       break;
+    case NS_FORM_INPUT_EMAIL:
     case NS_FORM_INPUT_URL:
       {
         PRUnichar crlf[] = { PRUnichar('\r'), PRUnichar('\n'), 0 };
         aValue.StripChars(crlf);
 
         aValue = nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(aValue);
       }
       break;
--- a/content/html/content/test/forms/test_input_email.html
+++ b/content/html/content/test/forms/test_input_email.html
@@ -70,18 +70,22 @@ function testEmailAddress(aElement, aVal
 }
 
 var email = document.forms[0].elements[0];
 
 // Simple values, checking the e-mail syntax validity.
 var values = [
   [ '', true ], // The empty string shouldn't be considered as invalid.
   [ 'foo@bar.com', true ],
-  [ ' foo@bar.com', false ],
-  [ 'foo@bar.com ', false ],
+  [ ' foo@bar.com', true ],
+  [ 'foo@bar.com ', true ],
+  [ '\r\n foo@bar.com', true ],
+  [ 'foo@bar.com \n\r', true ],
+  [ '\n\n \r\rfoo@bar.com\n\n   \r\r', true ],
+  [ '\n\r \n\rfoo@bar.com\n\r   \n\r', true ],
   [ 'tulip', false ],
   // Some checks on the user part of the address.
   [ '@bar.com', false ],
   [ 'f\noo@bar.com', true ],
   [ 'f\roo@bar.com', true ],
   [ 'f\r\noo@bar.com', true ],
   // Some checks for the domain part.
   [ 'foo@bar', true ],
@@ -158,17 +162,17 @@ for each (c in legalCharacters) {
   values.push(["foo@foo.bar" + c, true]);
 }
 // Add the concatenation of all legal characters too.
 values.push(["foo@bar.com" + legalCharacters, true]);
 
 // Add domain illegal characters.
 illegalCharacters = "()<>[]:;@\\,!#$%&'*+/=?^_`{|}~ \t";
 for each (c in illegalCharacters) {
-  values.push(['foo@foo.bar' + c, false]);
+  values.push(['foo@foo.ba' + c + 'r', false]);
 }
 
 values.forEach(function([value, valid]) {
   testEmailAddress(email, value, false, valid);
 });
 
 multipleValues.forEach(function([value, valid]) {
   testEmailAddress(email, value, true, valid);
--- a/content/html/content/test/test_bug549475.html
+++ b/content/html/content/test/test_bug549475.html
@@ -42,19 +42,19 @@ var valueModeValue =
 
 function sanitizeValue(aType, aValue)
 {
   switch (aType) {
     case "text":
     case "password":
     case "search":
     case "tel":
-    case "email":
       return aValue.replace(/[\n\r]/g, "");
     case "url":
+    case "email":
       return aValue.replace(/[\n\r]/g, "").replace(/^\s+|\s+$/g, "");
     case "date":
     case "month":
     case "week":
     case "time":
     case "datetime":
     case "datetime-local":
       // TODO: write the sanitize algorithm.