Bug 856265 -- Fix HTMLInputElement::GetValueAsDate to accept long string of numbers as input r=jst
☠☠ backed out by 3cb985aa114c ☠ ☠
authorGiovanni Sferro <agi.novanta@gmail.com>
Fri, 28 Mar 2014 17:33:39 -0700
changeset 176424 0779a3cf6075cad283d06b1628912780a2d9a8dd
parent 176423 083cbb15c2a53f74b4d9caa14799e735637d4fd8
child 176425 0e01c0304046ee42b21551d671f7e583243064ba
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjst
bugs856265
milestone31.0a1
Bug 856265 -- Fix HTMLInputElement::GetValueAsDate to accept long string of numbers as input r=jst
content/html/content/src/HTMLInputElement.cpp
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -4666,28 +4666,20 @@ HTMLInputElement::GetValueAsDate(const n
  * -The day must be exactly 2 digit long, and 01 <= day <= maxday
  *  Where maxday is the number of days in the month 'month' and year 'year'
  */
 
   if (aValue.Length() < 10) {
     return false;
   }
 
-  uint32_t endOfYearOffset = 0;
-  for (; NS_IsAsciiDigit(aValue[endOfYearOffset]); ++endOfYearOffset);
-
-  // The year must be at least 4 digits long.
-  if (aValue[endOfYearOffset] != '-' || endOfYearOffset < 4) {
-    return false;
-  }
-
-  // Now, we know where is the next '-' and what should be the size of the
-  // string.
-  if (aValue[endOfYearOffset + 3] != '-' ||
-      aValue.Length() != 10 + (endOfYearOffset - 4)) {
+  uint32_t endOfYearOffset = aValue.Length() - 6;
+
+  if (aValue[endOfYearOffset]     != '-' || 
+      aValue[endOfYearOffset + 3] != '-') {
     return false;
   }
 
   nsresult ec;
   *aYear = PromiseFlatString(StringHead(aValue, endOfYearOffset)).ToInteger(&ec);
   if (NS_FAILED(ec) || *aYear == 0) {
     return false;
   }