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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLParserIdioms.cpp

Issue 1378613005: input[type=number] should not accept numbers ending with '.'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return value.isZero() ? Decimal(0) : value; 114 return value.isZero() ? Decimal(0) : value;
115 } 115 }
116 116
117 double parseToDoubleForNumberType(const String& string, double fallbackValue) 117 double parseToDoubleForNumberType(const String& string, double fallbackValue)
118 { 118 {
119 // http://www.whatwg.org/specs/web-apps/current-work/#floating-point-numbers 119 // http://www.whatwg.org/specs/web-apps/current-work/#floating-point-numbers
120 // String::toDouble() accepts leading + and whitespace characters, which are not valid here. 120 // String::toDouble() accepts leading + and whitespace characters, which are not valid here.
121 UChar firstCharacter = string[0]; 121 UChar firstCharacter = string[0];
122 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha racter)) 122 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha racter))
123 return fallbackValue; 123 return fallbackValue;
124 if (string.endsWith('.'))
125 return fallbackValue;
124 126
125 bool valid = false; 127 bool valid = false;
126 double value = string.toDouble(&valid); 128 double value = string.toDouble(&valid);
127 if (!valid) 129 if (!valid)
128 return fallbackValue; 130 return fallbackValue;
129 131
130 // NaN and infinity are considered valid by String::toDouble, but not valid here. 132 // NaN and infinity are considered valid by String::toDouble, but not valid here.
131 if (!std::isfinite(value)) 133 if (!std::isfinite(value))
132 return fallbackValue; 134 return fallbackValue;
133 135
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 string = StringImpl::create8BitIfPossible(characters, size); 411 string = StringImpl::create8BitIfPossible(characters, size);
410 else if (width == Force8Bit) 412 else if (width == Force8Bit)
411 string = String::make8BitFrom16BitSource(characters, size); 413 string = String::make8BitFrom16BitSource(characters, size);
412 else 414 else
413 string = String(characters, size); 415 string = String(characters, size);
414 416
415 return string; 417 return string;
416 } 418 }
417 419
418 } 420 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/imported/web-platform-tests/html/semantics/forms/the-input-element/number-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698