Changeset 156183 in webkit
- Timestamp:
- Sep 20, 2013, 11:31:53 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r156182 r156183 1 2013-09-20 Alexey Proskuryakov <ap@apple.com> 2 3 REGRESSION (r156140): Srcset tests are frequently crashing 4 https://bugs.webkit.org/show_bug.cgi?id=121695 5 6 Reviewed by Dean Jackson. 7 8 Returning a string created without copying bytes is not safe. It used to be OK 9 because a new string was immediately created by decodeURLEscapeSequences(). 10 But even that was not great, because decodeURLEscapeSequences() could potentially 11 return the same string, not a deep copy, if we decided to optimize it like that. 12 13 Also made a number of drive-by style fixes. 14 - It's URL, not Url. 15 - It's srcset, not srcSet. 16 - We don't add ".0" in floating point value initializers. It's particularly misleading 17 to initialize a float with 1.0, which is a double value. 18 - Renamed srcSetLength to srcsetAttributeLength to match srcsetAttribute variable 19 whose length it caches. 20 21 * html/parser/HTMLParserIdioms.cpp: 22 (WebCore::parseImagesWithScaleFromSrcsetAttribute): 23 (WebCore::bestFitSourceForImageAttributes): 24 1 25 2013-09-19 Martin Robinson <mrobinson@igalia.com> 2 26 -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp
r156140 r156183 322 322 // See the specifications for more details about the algorithm to follow. 323 323 // http://www.w3.org/TR/2013/WD-html-srcset-20130228/#processing-the-image-candidates. 324 static void parseImagesWithScaleFromSrcSetAttribute(const String& srcSetAttribute, ImageCandidates& imageCandidates) 325 { 324 static void parseImagesWithScaleFromSrcsetAttribute(const String& srcsetAttribute, ImageCandidates& imageCandidates) 325 { 326 ASSERT(imageCandidates.isEmpty()); 327 326 328 size_t imageCandidateStart = 0; 327 unsigned src SetLength = srcSetAttribute.length();328 329 while (imageCandidateStart < src SetLength) {330 float im gScaleFactor = 1.0;329 unsigned srcsetAttributeLength = srcsetAttribute.length(); 330 331 while (imageCandidateStart < srcsetAttributeLength) { 332 float imageScaleFactor = 1; 331 333 size_t separator; 332 334 333 335 // 4. Splitting loop: Skip whitespace. 334 size_t imageU rlStart = srcSetAttribute.find(isNotHTMLSpace, imageCandidateStart);335 if (imageU rlStart == notFound)336 size_t imageURLStart = srcsetAttribute.find(isNotHTMLSpace, imageCandidateStart); 337 if (imageURLStart == notFound) 336 338 break; 337 339 // If The current candidate is either totally empty or only contains space, skipping. 338 if (src SetAttribute[imageUrlStart] == ',') {339 imageCandidateStart = imageU rlStart + 1;340 if (srcsetAttribute[imageURLStart] == ',') { 341 imageCandidateStart = imageURLStart + 1; 340 342 continue; 341 343 } 342 344 // 5. Collect a sequence of characters that are not space characters, and let that be url. 343 size_t imageU rlEnd = srcSetAttribute.find(isHTMLSpace, imageUrlStart + 1);344 if (imageU rlEnd == notFound) {345 imageU rlEnd = srcSetLength;346 separator = src SetLength;347 } else if (src SetAttribute[imageUrlEnd - 1] == ',') {348 --imageU rlEnd;349 separator = imageU rlEnd;345 size_t imageURLEnd = srcsetAttribute.find(isHTMLSpace, imageURLStart + 1); 346 if (imageURLEnd == notFound) { 347 imageURLEnd = srcsetAttributeLength; 348 separator = srcsetAttributeLength; 349 } else if (srcsetAttribute[imageURLEnd - 1] == ',') { 350 --imageURLEnd; 351 separator = imageURLEnd; 350 352 } else { 351 353 // 7. Collect a sequence of characters that are not "," (U+002C) characters, and let that be descriptors. 352 size_t imageScaleStart = src SetAttribute.find(isNotHTMLSpace, imageUrlEnd + 1);354 size_t imageScaleStart = srcsetAttribute.find(isNotHTMLSpace, imageURLEnd + 1); 353 355 if (imageScaleStart == notFound) 354 separator = src SetLength;355 else if (src SetAttribute[imageScaleStart] == ',')356 separator = srcsetAttributeLength; 357 else if (srcsetAttribute[imageScaleStart] == ',') 356 358 separator = imageScaleStart; 357 359 else { 358 360 // This part differs from the spec as the current implementation only supports pixel density descriptors for now. 359 size_t imageScaleEnd = src SetAttribute.find(isHTMLSpaceOrComma, imageScaleStart + 1);360 imageScaleEnd = (imageScaleEnd == notFound) ? src SetLength : imageScaleEnd;361 size_t imageScaleEnd = srcsetAttribute.find(isHTMLSpaceOrComma, imageScaleStart + 1); 362 imageScaleEnd = (imageScaleEnd == notFound) ? srcsetAttributeLength : imageScaleEnd; 361 363 size_t commaPosition = imageScaleEnd; 362 364 // Make sure there are no other descriptors. 363 while ((commaPosition < src SetLength - 1) && isHTMLSpace(srcSetAttribute[commaPosition]))365 while ((commaPosition < srcsetAttributeLength - 1) && isHTMLSpace(srcsetAttribute[commaPosition])) 364 366 ++commaPosition; 365 367 // If the first not html space character after the scale modifier is not a comma, 366 368 // the current candidate is an invalid input. 367 if ((commaPosition < src SetLength - 1) && srcSetAttribute[commaPosition] != ',') {369 if ((commaPosition < srcsetAttributeLength - 1) && srcsetAttribute[commaPosition] != ',') { 368 370 // Find the nearest comma and skip the input. 369 commaPosition = src SetAttribute.find(',', commaPosition + 1);371 commaPosition = srcsetAttribute.find(',', commaPosition + 1); 370 372 if (commaPosition == notFound) 371 373 break; … … 374 376 } 375 377 separator = commaPosition; 376 if (src SetAttribute[imageScaleEnd - 1] != 'x') {378 if (srcsetAttribute[imageScaleEnd - 1] != 'x') { 377 379 imageCandidateStart = separator + 1; 378 380 continue; … … 380 382 bool validScaleFactor = false; 381 383 size_t scaleFactorLengthWithoutUnit = imageScaleEnd - imageScaleStart - 1; 382 im gScaleFactor = charactersToFloat(srcSetAttribute.characters() + imageScaleStart, scaleFactorLengthWithoutUnit, &validScaleFactor);384 imageScaleFactor = charactersToFloat(srcsetAttribute.characters() + imageScaleStart, scaleFactorLengthWithoutUnit, &validScaleFactor); 383 385 384 386 if (!validScaleFactor) { … … 389 391 } 390 392 ImageWithScale image; 391 image.imageURL = String Impl::createWithoutCopying(srcSetAttribute.characters() + imageUrlStart, imageUrlEnd - imageUrlStart);392 image.scaleFactor = im gScaleFactor;393 image.imageURL = String(srcsetAttribute.characters() + imageURLStart, imageURLEnd - imageURLStart); 394 image.scaleFactor = imageScaleFactor; 393 395 394 396 imageCandidates.append(image); … … 398 400 } 399 401 400 String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& src SetAttribute)402 String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& srcsetAttribute) 401 403 { 402 404 ImageCandidates imageCandidates; 403 405 404 parseImagesWithScaleFromSrc SetAttribute(srcSetAttribute, imageCandidates);406 parseImagesWithScaleFromSrcsetAttribute(srcsetAttribute, imageCandidates); 405 407 406 408 const String src = srcAttribute.simplifyWhiteSpace(isHTMLSpace);
Note:
See TracChangeset
for help on using the changeset viewer.