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

Side by Side Diff: Source/core/html/parser/HTMLSrcsetParser.cpp

Issue 1306743003: Fix float parsing in srcset (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: switched clamp to cast Created 5 years, 4 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) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 template<typename CharType> 90 template<typename CharType>
91 float toFloat(const CharType* attribute, bool& isValid) 91 float toFloat(const CharType* attribute, bool& isValid)
92 { 92 {
93 // Make sure the is a valid floating point number 93 // Make sure the is a valid floating point number
94 // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floa ting-point-number 94 // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floa ting-point-number
95 unsigned lengthExcludingDescriptor = length - 1; 95 unsigned lengthExcludingDescriptor = length - 1;
96 if (lengthExcludingDescriptor > 0 && *(attribute + start) == '+') { 96 if (lengthExcludingDescriptor > 0 && *(attribute + start) == '+') {
97 isValid = false; 97 isValid = false;
98 return 0; 98 return 0;
99 } 99 }
100 return charactersToFloat(attribute + start, lengthExcludingDescriptor, & isValid); 100 Decimal result = parseToDecimalForNumberType(String(attribute + start, l engthExcludingDescriptor));
101 isValid = result.isFinite();
102 if (!isValid)
103 return 0;
104 return static_cast<float>(result.toDouble());
101 } 105 }
102 }; 106 };
103 107
104 template<typename CharType> 108 template<typename CharType>
105 static void appendDescriptorAndReset(const CharType* attributeStart, const CharT ype*& descriptorStart, const CharType* position, Vector<DescriptorToken>& descri ptors) 109 static void appendDescriptorAndReset(const CharType* attributeStart, const CharT ype*& descriptorStart, const CharType* position, Vector<DescriptorToken>& descri ptors)
106 { 110 {
107 if (position > descriptorStart) 111 if (position > descriptorStart)
108 descriptors.append(DescriptorToken(descriptorStart - attributeStart, pos ition - descriptorStart)); 112 descriptors.append(DescriptorToken(descriptorStart - attributeStart, pos ition - descriptorStart));
109 descriptorStart = 0; 113 descriptorStart = 0;
110 } 114 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 Vector<ImageCandidate> imageCandidates; 435 Vector<ImageCandidate> imageCandidates;
432 imageCandidates.append(srcsetImageCandidate); 436 imageCandidates.append(srcsetImageCandidate);
433 437
434 if (!srcAttribute.isEmpty()) 438 if (!srcAttribute.isEmpty())
435 imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.leng th(), DescriptorParsingResult(), ImageCandidate::SrcOrigin)); 439 imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.leng th(), DescriptorParsingResult(), ImageCandidate::SrcOrigin));
436 440
437 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates ).toString(); 441 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates ).toString();
438 } 442 }
439 443
440 } 444 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698