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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.cpp

Issue 1914693002: Clamp CSS numbers to float range at parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/parser/CSSParserFastPaths.h" 5 #include "core/css/parser/CSSParserFastPaths.h"
6 6
7 #include "core/StylePropertyShorthand.h" 7 #include "core/StylePropertyShorthand.h"
8 #include "core/css/CSSFunctionValue.h" 8 #include "core/css/CSSFunctionValue.h"
9 #include "core/css/CSSValuePool.h" 9 #include "core/css/CSSValuePool.h"
10 #include "core/css/parser/CSSParserIdioms.h" 10 #include "core/css/parser/CSSParserIdioms.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } else if (length > 1 && characters[length - 1] == '%') { 76 } else if (length > 1 && characters[length - 1] == '%') {
77 length -= 1; 77 length -= 1;
78 unit = CSSPrimitiveValue::UnitType::Percentage; 78 unit = CSSPrimitiveValue::UnitType::Percentage;
79 } 79 }
80 80
81 // We rely on charactersToDouble for validation as well. The function 81 // We rely on charactersToDouble for validation as well. The function
82 // will set "ok" to "false" if the entire passed-in character range does 82 // will set "ok" to "false" if the entire passed-in character range does
83 // not represent a double. 83 // not represent a double.
84 bool ok; 84 bool ok;
85 number = charactersToDouble(characters, length, &ok); 85 number = charactersToDouble(characters, length, &ok);
86 return ok && CSSPropertyParser::isValidNumericValue(number); 86 if (!std::isfinite(number)) {
rune 2016/04/25 12:24:29 Should this be std::isnan instead?
87 ok = false;
88 } else {
89 number = clampTo<float>(number);
90 }
91 return ok;
87 } 92 }
88 93
89 static CSSValue* parseSimpleLengthValue(CSSPropertyID propertyId, const String& string, CSSParserMode cssParserMode) 94 static CSSValue* parseSimpleLengthValue(CSSPropertyID propertyId, const String& string, CSSParserMode cssParserMode)
90 { 95 {
91 ASSERT(!string.isEmpty()); 96 ASSERT(!string.isEmpty());
92 bool acceptsNegativeNumbers = false; 97 bool acceptsNegativeNumbers = false;
93 98
94 // In @viewport, width and height are shorthands, not simple length values. 99 // In @viewport, width and height are shorthands, not simple length values.
95 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp ertyID(propertyId, acceptsNegativeNumbers)) 100 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp ertyID(propertyId, acceptsNegativeNumbers))
96 return nullptr; 101 return nullptr;
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 if (isColorPropertyID(propertyID)) 1033 if (isColorPropertyID(propertyID))
1029 return parseColor(string, parserMode); 1034 return parseColor(string, parserMode);
1030 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode)) 1035 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode))
1031 return keyword; 1036 return keyword;
1032 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) 1037 if (CSSValue* transform = parseSimpleTransform(propertyID, string))
1033 return transform; 1038 return transform;
1034 return nullptr; 1039 return nullptr;
1035 } 1040 }
1036 1041
1037 } // namespace blink 1042 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698