Align srcset attribute parsing with the HTML specification
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Sep 2016 22:59:29 +0000 (22:59 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Sep 2016 22:59:29 +0000 (22:59 +0000)
commit671f722a63f20c670656e9fba72997a4e775c5a9
tree0c138580456e6fde86b5569ff9cf3c7fc016ecb1
parent7e230ffb5e161e3c360c476d39fe765787f41d02
Align srcset attribute parsing with the HTML specification
https://bugs.webkit.org/show_bug.cgi?id=161636

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline a couple of W3C tests now that more checks are passing.

* web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt:
* web-platform-tests/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute-expected.txt:

Source/WebCore:

Align srcset attribute parsing with the HTML specification:
- https://html.spec.whatwg.org/#parse-a-srcset-attribute

The new behavior is also consistent with Firefox and Chrome
as all 3 browsers now pass 100% of the checks at:
- http://w3c-test.org/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html

No new tests, rebaselined existing tests.

* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseValidHTMLNonNegativeIntegerInternal):
(WebCore::parseValidHTMLNonNegativeInteger):
(WebCore::parseValidHTMLFloatingPointNumberInternal):
(WebCore::parseValidHTMLFloatingPointNumber):
* html/parser/HTMLParserIdioms.h:
Add convenience for parsing *valid* HTML non-negative integers and
*valid* floating point number values.

* html/parser/HTMLSrcsetParser.cpp:
(WebCore::parseDescriptors):
- Use parseValidHTMLFloatingPointNumber() to parse density so that the value
  is parsed as a valid HTML floating point number value, as per the spec.
- Use parseValidHTMLNonNegativeInteger() to parse width and height so that
  the value is parsed as a valid HTML non-negative integer value, as per the
  spec.
- Return false if descriptor does not have a h, w and x at the end as per:
  https://html.spec.whatwg.org/#parse-a-srcset-attribute (step 13: Anything else)
- Return false if height is set but not width, as per:
  https://html.spec.whatwg.org/#parse-a-srcset-attribute (step 14)

(WebCore::parseImageCandidatesFromSrcsetAttribute):
- Skip whitespace if URL does not end with a comma instead of assuming there is
  a single space character, as per:
  https://html.spec.whatwg.org/#parse-a-srcset-attribute (step 8. Otherwise 1.)

LayoutTests:

Re-sync fast/hidpi/image-srcset-invalid-descriptor.html with Blink.

* fast/hidpi/image-srcset-invalid-descriptor-expected.txt:
* fast/hidpi/image-srcset-invalid-descriptor.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205515 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/hidpi/image-srcset-invalid-descriptor-expected.txt
LayoutTests/fast/hidpi/image-srcset-invalid-descriptor.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLParserIdioms.cpp
Source/WebCore/html/parser/HTMLParserIdioms.h
Source/WebCore/html/parser/HTMLSrcsetParser.cpp