From 720fac23279e4bbce928cfdecd66ba08580b2614 Mon Sep 17 00:00:00 2001 From: Giovanni Sferro Date: Tue, 15 Apr 2014 10:45:05 -0400 Subject: [PATCH] Bug 856265 - Fix HTMLInputElement::GetValueAsDate to accept long string of numbers as input. r=jst --- content/html/content/src/HTMLInputElement.cpp | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/content/html/content/src/HTMLInputElement.cpp b/content/html/content/src/HTMLInputElement.cpp index 8e1ba6c331ab..f640ba522d81 100644 --- a/content/html/content/src/HTMLInputElement.cpp +++ b/content/html/content/src/HTMLInputElement.cpp @@ -4674,24 +4674,15 @@ HTMLInputElement::GetValueAsDate(const nsAString& aValue, 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) { + uint32_t endOfYearOffset = aValue.Length() - 6; + + if (aValue[endOfYearOffset] != '-' || + aValue[endOfYearOffset + 3] != '-') { 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)) { - return false; - } - - nsresult ec; - *aYear = PromiseFlatString(StringHead(aValue, endOfYearOffset)).ToInteger(&ec); - if (NS_FAILED(ec) || *aYear == 0) { + if (!DigitSubStringToNumber(aValue, 0, endOfYearOffset, aYear) || + *aYear < 1) { return false; }