Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1169)

Unified Diff: Source/core/html/parser/HTMLParserIdioms.cpp

Issue 235273003: parsing input type=number should skip spaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/parser/HTMLParserIdioms.cpp
diff --git a/Source/core/html/parser/HTMLParserIdioms.cpp b/Source/core/html/parser/HTMLParserIdioms.cpp
index a71d9a54fac468194b7e3214334c3b4862f4ca14..a3f8810b27fe239281fce3f22b62a550cfcfea6d 100644
--- a/Source/core/html/parser/HTMLParserIdioms.cpp
+++ b/Source/core/html/parser/HTMLParserIdioms.cpp
@@ -93,10 +93,16 @@ String serializeForNumberType(double number)
return String::numberToStringECMAScript(number);
}
-Decimal parseToDecimalForNumberType(const String& string, const Decimal& fallbackValue)
+static bool isSpaceCharacter(UChar c)
+{
+ return c == ' ';
+}
+
+Decimal parseToDecimalForNumberType(const String& numberString, const Decimal& fallbackValue)
tkent 2014/04/14 00:47:37 Do not modify this function. The behavior of this
{
// http://www.whatwg.org/specs/web-apps/current-work/#floating-point-numbers and parseToDoubleForNumberType
// String::toDouble() accepts leading + and whitespace characters, which are not valid here.
+ String string = numberString.removeCharacters(isSpaceCharacter);
const UChar firstCharacter = string[0];
if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCharacter))
return fallbackValue;
@@ -114,10 +120,11 @@ Decimal parseToDecimalForNumberType(const String& string, const Decimal& fallbac
return value.isZero() ? Decimal(0) : value;
}
-double parseToDoubleForNumberType(const String& string, double fallbackValue)
+double parseToDoubleForNumberType(const String& numberString, double fallbackValue)
tkent 2014/04/14 00:47:37 Ditto.
{
// http://www.whatwg.org/specs/web-apps/current-work/#floating-point-numbers
// String::toDouble() accepts leading + and whitespace characters, which are not valid here.
+ String string = numberString.removeCharacters(isSpaceCharacter);
UChar firstCharacter = string[0];
if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCharacter))
return fallbackValue;

Powered by Google App Engine
This is Rietveld 408576698