Changeset 205515 in webkit


Ignore:
Timestamp:
Sep 6, 2016 3:59:29 PM (8 years ago)
Author:
Chris Dumez
Message:

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:

The new behavior is also consistent with Firefox and Chrome
as all 3 browsers now pass 100% of the checks at:

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):

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:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205514 r205515  
     12016-09-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Align srcset attribute parsing with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=161636
     5
     6        Reviewed by Darin Adler.
     7
     8        Re-sync fast/hidpi/image-srcset-invalid-descriptor.html with Blink.
     9
     10        * fast/hidpi/image-srcset-invalid-descriptor-expected.txt:
     11        * fast/hidpi/image-srcset-invalid-descriptor.html:
     12
    1132016-09-06  Ryan Haddad  <ryanhaddad@apple.com>
    214
  • trunk/LayoutTests/fast/hidpi/image-srcset-invalid-descriptor-expected.txt

    r177772 r205515  
    1 PASS document.getElementById("invalid_with_x").clientWidth is 100
    2 PASS document.getElementById("invalid_without_x").clientWidth is 100
    3 PASS document.getElementById("future_descriptor").clientWidth is 100
    4 PASS document.getElementById("future_descriptor_without_x").clientWidth is 100
    5 PASS document.getElementById("x_with_w_ignored").clientWidth is 200
    6 PASS document.getElementById("x_with_h_ignored").clientWidth is 200
     1PASS document.getElementById("foo").clientWidth==200 is true
     2PASS document.getElementById("foo2").clientWidth==200 is true
     3PASS document.getElementById("foo3").clientWidth==200 is true
     4PASS document.getElementById("foo4").clientWidth==200 is true
     5PASS document.getElementById("foo5").clientWidth==200 is true
     6PASS document.getElementById("foo6").clientWidth==200 is true
     7PASS document.getElementById("foo7").clientWidth==200 is true
     8PASS document.getElementById("foo8").clientWidth==200 is true
     9PASS document.getElementById("foo9").clientWidth==200 is true
     10PASS document.getElementById("foo10").clientWidth==200 is true
    711PASS successfullyParsed is true
    812
    913TEST COMPLETE
    10 This test passes if the image below is a 100px blue square when the deviceScaleFactor is 1.
    11 It tests that even though the 1x resource contains many invalid descriptors, only the invalid descriptors are ignored (according to the spec).
     14This test passes if the image below is a 200px green square when the deviceScaleFactor is 1.
     15It tests that the 1x resource is ignored since it contains invalid descriptors.
     16The 2x resource has an intrinsic width of 200px, since it's a 400px wide image at 2x DPR.
    1217         
  • trunk/LayoutTests/fast/hidpi/image-srcset-invalid-descriptor.html

    r178721 r205515  
    1 <html>
    2 <head>
     1<!DOCTYPE html>
    32<script>
    43    window.targetScaleFactor = 1;
    54</script>
    6 <script src="../../resources/srcset-helper.js"></script>
     5<script src="resources/srcset-helper.js"></script>
    76<script src="../../resources/js-test.js"></script>
    87<script>
    9     function runTest() {
    10         shouldBe('document.getElementById("invalid_with_x").clientWidth', '100');
    11         shouldBe('document.getElementById("invalid_without_x").clientWidth', '100');
    12         shouldBe('document.getElementById("future_descriptor").clientWidth', '100');
    13         shouldBe('document.getElementById("future_descriptor_without_x").clientWidth', '100');
    14         shouldBe('document.getElementById("x_with_w_ignored").clientWidth', '200');
    15         shouldBe('document.getElementById("x_with_h_ignored").clientWidth', '200');
    16     }
     8    addEventListener("load", function() {
     9        shouldBeTrue('document.getElementById("foo").clientWidth==200');
     10        shouldBeTrue('document.getElementById("foo2").clientWidth==200');
     11        shouldBeTrue('document.getElementById("foo3").clientWidth==200');
     12        shouldBeTrue('document.getElementById("foo4").clientWidth==200');
     13        shouldBeTrue('document.getElementById("foo5").clientWidth==200');
     14        shouldBeTrue('document.getElementById("foo6").clientWidth==200');
     15        shouldBeTrue('document.getElementById("foo7").clientWidth==200');
     16        shouldBeTrue('document.getElementById("foo8").clientWidth==200');
     17        shouldBeTrue('document.getElementById("foo9").clientWidth==200');
     18        shouldBeTrue('document.getElementById("foo10").clientWidth==200');
     19    }, false);
    1720</script>
    18 </head>
    19 
    20 <body id="body">
    21     <div>This test passes if the image below is a 100px blue square when the deviceScaleFactor is 1.</div>
    22     <div> It tests that even though the 1x resource contains many invalid descriptors,
    23         only the invalid descriptors are ignored (according to the spec).</div>
    24     <img id="invalid_with_x" src="" srcset="resources/blue-100-px-square.png 43q 1x dfs 3dd, resources/green-400-px-square.png 2x">
    25     <img id="invalid_without_x" src="" srcset="resources/blue-100-px-square.png 300q, resources/green-400-px-square.png 2x">
    26     <img id="future_descriptor" srcset=",resources/blue-100-px-square.png 1x future-descriptor(3x, 4h, whatever), resources/green-400-px-square.png 2x">
    27     <img id="future_descriptor_without_x" srcset=",resources/blue-100-px-square.png future-descriptor(3x, 4h, whatever), resources/green-400-px-square.png 2x">
    28     <img id="x_with_w_ignored" srcset=",resources/blue-100-px-square.png 1x 100w, resources/green-400-px-square.png 2x">
    29     <img id="x_with_h_ignored" srcset=",resources/blue-100-px-square.png 1x 100h, resources/green-400-px-square.png 2x">
    30 </body>
    31 </html>
     21<div>This test passes if the image below is a 200px green square when the deviceScaleFactor is 1.</div>
     22<div>It tests that the 1x resource is ignored since it contains invalid descriptors.</div>
     23<div>The 2x resource has an intrinsic width of 200px, since it's a 400px wide image at 2x DPR.</div>
     24<img id="foo" src="" srcset="resources/blue-100-px-square.png 43q 1x dfs 3dd, resources/green-400-px-square.png 2x">
     25<img id="foo2" src="" srcset="resources/blue-100-px-square.png 300q, resources/green-400-px-square.png 2x">
     26<img id="foo3" src="" srcset="resources/blue-100-px-square.png 100w 100w, resources/green-400-px-square.png 2x">
     27<img id="foo4" src="" srcset="resources/blue-100-px-square.png 100h 100h, resources/green-400-px-square.png 2x">
     28<img id="foo5" src="" srcset="resources/blue-100-px-square.png 100x 100h, resources/green-400-px-square.png 2x">
     29<img id="foo6" src="" srcset="resources/blue-100-px-square.png 100x 100w, resources/green-400-px-square.png 2x">
     30<img id="foo7" src="" srcset="resources/blue-100-px-square.png -100w, resources/green-400-px-square.png 2x">
     31<img id="foo8" src="" srcset="resources/blue-100-px-square.png -100h, resources/green-400-px-square.png 2x">
     32<img id="foo9" src="" srcset="resources/blue-100-px-square.png -1x, resources/green-400-px-square.png 2x">
     33<img id="foo10" src="" srcset="resources/blue-100-px-square.png 100h, resources/green-400-px-square.png 2x">
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r205473 r205515  
     12016-09-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Align srcset attribute parsing with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=161636
     5
     6        Reviewed by Darin Adler.
     7
     8        Rebaseline a couple of W3C tests now that more checks are passing.
     9
     10        * web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt:
     11        * web-platform-tests/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute-expected.txt:
     12
    1132016-09-06  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt

    r204090 r205515  
    55FAIL <img srcset="/images/green-256x256.png 2x" data-expect="128"> assert_equals: naturalWidth expected 128 but got 256
    66FAIL <img srcset="/images/green-256x256.png 10000x" data-expect="0"> assert_equals: naturalWidth expected 0 but got 256
    7 FAIL <img srcset="/images/green-256x256.png 9e99999999999999999999999x" data-expect="0"> assert_equals: naturalWidth expected 0 but got 256
     7PASS <img srcset="/images/green-256x256.png 9e99999999999999999999999x" data-expect="0">
    88PASS <img srcset="/images/green-256x256.png 256w" sizes="256px" data-expect="256">
    99FAIL <img srcset="/images/green-256x256.png 512w" sizes="256px" data-expect="128"> assert_equals: naturalWidth expected 128 but got 256
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute-expected.txt

    r204090 r205515  
    2727PASS "data:,a 1x "
    2828PASS "data:,a 1x,"
    29 FAIL "data:,a ( , data:,b 1x, ), data:,c" assert_equals: expected "data:,c" but got "data:,a"
    30 FAIL "data:,a ((( , data:,b 1x, ), data:,c" assert_equals: expected "data:,c" but got "data:,a"
    31 FAIL "data:,a [ , data:,b 1x, ], data:,c" assert_equals: expected "data:,b" but got "data:,a"
    32 FAIL "data:,a { , data:,b 1x, }, data:,c" assert_equals: expected "data:,b" but got "data:,a"
    33 FAIL "data:,a \" , data:,b 1x, \", data:,c" assert_equals: expected "data:,b" but got "data:,a"
    34 FAIL "data:,a \\,data:;\,b, data:,c" assert_equals: expected "data:;\\,b" but got "data:,a"
     29PASS "data:,a ( , data:,b 1x, ), data:,c"
     30PASS "data:,a ((( , data:,b 1x, ), data:,c"
     31PASS "data:,a [ , data:,b 1x, ], data:,c"
     32PASS "data:,a { , data:,b 1x, }, data:,c"
     33PASS "data:,a \" , data:,b 1x, \", data:,c"
     34PASS "data:,a \\,data:;\,b, data:,c"
    3535PASS "data:,a, data:,b ("
    3636PASS "data:,a, data:,b (  "
     
    3838PASS "data:,a, data:,b (x"
    3939PASS "data:,a, data:,b ()"
    40 FAIL "data:,a (, data:,b" assert_equals: expected "" but got "data:,a"
    41 FAIL "data:,a /*, data:,b, data:,c */" assert_equals: expected "data:,b" but got "data:,a"
    42 FAIL "data:,a //, data:,b" assert_equals: expected "data:,b" but got "data:,a"
    43 FAIL "data:,a foo" assert_equals: expected "" but got "data:,a"
    44 FAIL "data:,a foo foo" assert_equals: expected "" but got "data:,a"
    45 FAIL "data:,a foo 1x" assert_equals: expected "" but got "data:,a"
    46 FAIL "data:,a foo 1x foo" assert_equals: expected "" but got "data:,a"
    47 FAIL "data:,a foo 1w" assert_equals: expected "" but got "data:,a"
    48 FAIL "data:,a foo 1w foo" assert_equals: expected "" but got "data:,a"
     40PASS "data:,a (, data:,b"
     41PASS "data:,a /*, data:,b, data:,c */"
     42PASS "data:,a //, data:,b"
     43PASS "data:,a foo"
     44PASS "data:,a foo foo"
     45PASS "data:,a foo 1x"
     46PASS "data:,a foo 1x foo"
     47PASS "data:,a foo 1w"
     48PASS "data:,a foo 1w foo"
    4949PASS "data:,a 1x 1x"
    5050PASS "data:,a 1w 1w"
     
    5858PASS "data:,a 1x 1w 1h"
    5959PASS "data:,a 1w"
    60 FAIL "data:,a 1h" assert_equals: expected "" but got "data:,a"
    61 FAIL "data:,a 1h foo" assert_equals: expected "" but got "data:,a"
    62 FAIL "data:,a foo 1h" assert_equals: expected "" but got "data:,a"
     60PASS "data:,a 1h"
     61PASS "data:,a 1h foo"
     62PASS "data:,a foo 1h"
    6363PASS "data:,a 0w"
    6464PASS "data:,a -1w"
    6565PASS "data:,a 1w -1w"
    66 FAIL "data:,a 1.0w" assert_equals: expected "" but got "data:,a"
     66PASS "data:,a 1.0w"
    6767PASS "data:,a 1w 1.0w"
    68 FAIL "data:,a 1e0w" assert_equals: expected "" but got "data:,a"
     68PASS "data:,a 1e0w"
    6969PASS "data:,a 1w 1e0w"
    70 FAIL "data:,a 1www" assert_equals: expected "" but got "data:,a"
     70PASS "data:,a 1www"
    7171PASS "data:,a 1w 1www"
    72 FAIL "data:,a +1w" assert_equals: expected "" but got "data:,a"
     72PASS "data:,a +1w"
    7373PASS "data:,a 1w +1w"
    74 FAIL "data:,a 1W" assert_equals: expected "" but got "data:,a"
    75 FAIL "data:,a 1w 1W" assert_equals: expected "" but got "data:,a"
     74PASS "data:,a 1W"
     75PASS "data:,a 1w 1W"
    7676PASS "data:,a Infinityw"
    7777PASS "data:,a 1w Infinityw"
     
    8080PASS "data:,a 0x1w"
    8181PASS "data:,a 0X1w"
    82 FAIL "data:,a 1\x01w" (trailing U+0001) assert_equals: expected "" but got "data:,a"
    83 FAIL "data:,a 1 w" (trailing U+00A0) assert_equals: expected "" but got "data:,a"
    84 FAIL "data:,a 1 w" (trailing U+1680) assert_equals: expected "" but got "data:,a"
    85 FAIL "data:,a 1 w" (trailing U+2000) assert_equals: expected "" but got "data:,a"
    86 FAIL "data:,a 1 w" (trailing U+2001) assert_equals: expected "" but got "data:,a"
    87 FAIL "data:,a 1 w" (trailing U+2002) assert_equals: expected "" but got "data:,a"
    88 FAIL "data:,a 1 w" (trailing U+2003) assert_equals: expected "" but got "data:,a"
    89 FAIL "data:,a 1 w" (trailing U+2004) assert_equals: expected "" but got "data:,a"
    90 FAIL "data:,a 1 w" (trailing U+2005) assert_equals: expected "" but got "data:,a"
    91 FAIL "data:,a 1 w" (trailing U+2006) assert_equals: expected "" but got "data:,a"
    92 FAIL "data:,a 1 w" (trailing U+2007) assert_equals: expected "" but got "data:,a"
    93 FAIL "data:,a 1 w" (trailing U+2008) assert_equals: expected "" but got "data:,a"
    94 FAIL "data:,a 1 w" (trailing U+2009) assert_equals: expected "" but got "data:,a"
    95 FAIL "data:,a 1 w" (trailing U+200A) assert_equals: expected "" but got "data:,a"
    96 FAIL "data:,a 1‌w" (trailing U+200C) assert_equals: expected "" but got "data:,a"
    97 FAIL "data:,a 1‍w" (trailing U+200D) assert_equals: expected "" but got "data:,a"
    98 FAIL "data:,a 1 w" (trailing U+202F) assert_equals: expected "" but got "data:,a"
    99 FAIL "data:,a 1 w" (trailing U+205F) assert_equals: expected "" but got "data:,a"
    100 FAIL "data:,a 1 w" (trailing U+3000) assert_equals: expected "" but got "data:,a"
    101 FAIL "data:,a 1w" (trailing U+FEFF) assert_equals: expected "" but got "data:,a"
     82PASS "data:,a 1\x01w" (trailing U+0001)
     83PASS "data:,a 1 w" (trailing U+00A0)
     84PASS "data:,a 1 w" (trailing U+1680)
     85PASS "data:,a 1 w" (trailing U+2000)
     86PASS "data:,a 1 w" (trailing U+2001)
     87PASS "data:,a 1 w" (trailing U+2002)
     88PASS "data:,a 1 w" (trailing U+2003)
     89PASS "data:,a 1 w" (trailing U+2004)
     90PASS "data:,a 1 w" (trailing U+2005)
     91PASS "data:,a 1 w" (trailing U+2006)
     92PASS "data:,a 1 w" (trailing U+2007)
     93PASS "data:,a 1 w" (trailing U+2008)
     94PASS "data:,a 1 w" (trailing U+2009)
     95PASS "data:,a 1 w" (trailing U+200A)
     96PASS "data:,a 1‌w" (trailing U+200C)
     97PASS "data:,a 1‍w" (trailing U+200D)
     98PASS "data:,a 1 w" (trailing U+202F)
     99PASS "data:,a 1 w" (trailing U+205F)
     100PASS "data:,a 1 w" (trailing U+3000)
     101PASS "data:,a 1w" (trailing U+FEFF)
    102102PASS "data:,a \x011w" (leading U+0001)
    103103PASS "data:,a  1w" (leading U+00A0)
    104 FAIL "data:,a  1w" (leading U+1680) assert_equals: expected "" but got "data:,a"
    105 FAIL "data:,a  1w" (leading U+2000) assert_equals: expected "" but got "data:,a"
    106 FAIL "data:,a  1w" (leading U+2001) assert_equals: expected "" but got "data:,a"
    107 FAIL "data:,a  1w" (leading U+2002) assert_equals: expected "" but got "data:,a"
    108 FAIL "data:,a  1w" (leading U+2003) assert_equals: expected "" but got "data:,a"
    109 FAIL "data:,a  1w" (leading U+2004) assert_equals: expected "" but got "data:,a"
    110 FAIL "data:,a  1w" (leading U+2005) assert_equals: expected "" but got "data:,a"
    111 FAIL "data:,a  1w" (leading U+2006) assert_equals: expected "" but got "data:,a"
    112 FAIL "data:,a  1w" (leading U+2007) assert_equals: expected "" but got "data:,a"
    113 FAIL "data:,a  1w" (leading U+2008) assert_equals: expected "" but got "data:,a"
    114 FAIL "data:,a  1w" (leading U+2009) assert_equals: expected "" but got "data:,a"
    115 FAIL "data:,a  1w" (leading U+200A) assert_equals: expected "" but got "data:,a"
     104PASS "data:,a  1w" (leading U+1680)
     105PASS "data:,a  1w" (leading U+2000)
     106PASS "data:,a  1w" (leading U+2001)
     107PASS "data:,a  1w" (leading U+2002)
     108PASS "data:,a  1w" (leading U+2003)
     109PASS "data:,a  1w" (leading U+2004)
     110PASS "data:,a  1w" (leading U+2005)
     111PASS "data:,a  1w" (leading U+2006)
     112PASS "data:,a  1w" (leading U+2007)
     113PASS "data:,a  1w" (leading U+2008)
     114PASS "data:,a  1w" (leading U+2009)
     115PASS "data:,a  1w" (leading U+200A)
    116116PASS "data:,a ‌1w" (leading U+200C)
    117117PASS "data:,a ‍1w" (leading U+200D)
    118118PASS "data:,a  1w" (leading U+202F)
    119 FAIL "data:,a  1w" (leading U+205F) assert_equals: expected "" but got "data:,a"
    120 FAIL "data:,a  1w" (leading U+3000) assert_equals: expected "" but got "data:,a"
     119PASS "data:,a  1w" (leading U+205F)
     120PASS "data:,a  1w" (leading U+3000)
    121121PASS "data:,a 1w" (leading U+FEFF)
    122122PASS "data:,a 0x"
     
    132132PASS "data:,a .x"
    133133PASS "data:,a -.x"
    134 FAIL "data:,a 1.x" assert_equals: expected "" but got "data:,a"
     134PASS "data:,a 1.x"
    135135PASS "data:,a .5x"
    136136PASS "data:,a .5e1x"
     
    139139PASS "data:,a 1.0x"
    140140PASS "data:,a 1x 1.0x"
    141 FAIL "data:,a +1x" assert_equals: expected "" but got "data:,a"
    142 FAIL "data:,a 1X" assert_equals: expected "" but got "data:,a"
     141PASS "data:,a +1x"
     142PASS "data:,a 1X"
    143143PASS "data:,a Infinityx"
    144144PASS "data:,a NaNx"
     
    187187PASS "data:,a 1w 0h"
    188188PASS "data:,a 1w -1h"
    189 FAIL "data:,a 1w 1.0h" assert_equals: expected "" but got "data:,a"
    190 FAIL "data:,a 1w 1e0h" assert_equals: expected "" but got "data:,a"
    191 FAIL "data:,a 1w 1hhh" assert_equals: expected "" but got "data:,a"
    192 FAIL "data:,a 1w +1h" assert_equals: expected "" but got "data:,a"
    193 FAIL "data:,a 1w 1H" assert_equals: expected "" but got "data:,a"
     189PASS "data:,a 1w 1.0h"
     190PASS "data:,a 1w 1e0h"
     191PASS "data:,a 1w 1hhh"
     192PASS "data:,a 1w +1h"
     193PASS "data:,a 1w 1H"
    194194PASS "data:,a 1w Infinityh"
    195195PASS "data:,a 1w NaNh"
    196196PASS "data:,a 0x1h"
    197197PASS "data:,a 0X1h"
    198 FAIL "data:,a 1w 1\x01h" (trailing U+0001) assert_equals: expected "" but got "data:,a"
    199 FAIL "data:,a 1w 1 h" (trailing U+00A0) assert_equals: expected "" but got "data:,a"
    200 FAIL "data:,a 1w 1 h" (trailing U+1680) assert_equals: expected "" but got "data:,a"
    201 FAIL "data:,a 1w 1 h" (trailing U+2000) assert_equals: expected "" but got "data:,a"
    202 FAIL "data:,a 1w 1 h" (trailing U+2001) assert_equals: expected "" but got "data:,a"
    203 FAIL "data:,a 1w 1 h" (trailing U+2002) assert_equals: expected "" but got "data:,a"
    204 FAIL "data:,a 1w 1 h" (trailing U+2003) assert_equals: expected "" but got "data:,a"
    205 FAIL "data:,a 1w 1 h" (trailing U+2004) assert_equals: expected "" but got "data:,a"
    206 FAIL "data:,a 1w 1 h" (trailing U+2005) assert_equals: expected "" but got "data:,a"
    207 FAIL "data:,a 1w 1 h" (trailing U+2006) assert_equals: expected "" but got "data:,a"
    208 FAIL "data:,a 1w 1 h" (trailing U+2007) assert_equals: expected "" but got "data:,a"
    209 FAIL "data:,a 1w 1 h" (trailing U+2008) assert_equals: expected "" but got "data:,a"
    210 FAIL "data:,a 1w 1 h" (trailing U+2009) assert_equals: expected "" but got "data:,a"
    211 FAIL "data:,a 1w 1 h" (trailing U+200A) assert_equals: expected "" but got "data:,a"
    212 FAIL "data:,a 1w 1‌h" (trailing U+200C) assert_equals: expected "" but got "data:,a"
    213 FAIL "data:,a 1w 1‍h" (trailing U+200D) assert_equals: expected "" but got "data:,a"
    214 FAIL "data:,a 1w 1 h" (trailing U+202F) assert_equals: expected "" but got "data:,a"
    215 FAIL "data:,a 1w 1 h" (trailing U+205F) assert_equals: expected "" but got "data:,a"
    216 FAIL "data:,a 1w 1 h" (trailing U+3000) assert_equals: expected "" but got "data:,a"
    217 FAIL "data:,a 1w 1h" (trailing U+FEFF) assert_equals: expected "" but got "data:,a"
     198PASS "data:,a 1w 1\x01h" (trailing U+0001)
     199PASS "data:,a 1w 1 h" (trailing U+00A0)
     200PASS "data:,a 1w 1 h" (trailing U+1680)
     201PASS "data:,a 1w 1 h" (trailing U+2000)
     202PASS "data:,a 1w 1 h" (trailing U+2001)
     203PASS "data:,a 1w 1 h" (trailing U+2002)
     204PASS "data:,a 1w 1 h" (trailing U+2003)
     205PASS "data:,a 1w 1 h" (trailing U+2004)
     206PASS "data:,a 1w 1 h" (trailing U+2005)
     207PASS "data:,a 1w 1 h" (trailing U+2006)
     208PASS "data:,a 1w 1 h" (trailing U+2007)
     209PASS "data:,a 1w 1 h" (trailing U+2008)
     210PASS "data:,a 1w 1 h" (trailing U+2009)
     211PASS "data:,a 1w 1 h" (trailing U+200A)
     212PASS "data:,a 1w 1‌h" (trailing U+200C)
     213PASS "data:,a 1w 1‍h" (trailing U+200D)
     214PASS "data:,a 1w 1 h" (trailing U+202F)
     215PASS "data:,a 1w 1 h" (trailing U+205F)
     216PASS "data:,a 1w 1 h" (trailing U+3000)
     217PASS "data:,a 1w 1h" (trailing U+FEFF)
    218218PASS "data:,a 1w \x011h" (leading U+0001)
    219219PASS "data:,a 1w  1h" (leading U+00A0)
    220 FAIL "data:,a 1w  1h" (leading U+1680) assert_equals: expected "" but got "data:,a"
    221 FAIL "data:,a 1w  1h" (leading U+2000) assert_equals: expected "" but got "data:,a"
    222 FAIL "data:,a 1w  1h" (leading U+2001) assert_equals: expected "" but got "data:,a"
    223 FAIL "data:,a 1w  1h" (leading U+2002) assert_equals: expected "" but got "data:,a"
    224 FAIL "data:,a 1w  1h" (leading U+2003) assert_equals: expected "" but got "data:,a"
    225 FAIL "data:,a 1w  1h" (leading U+2004) assert_equals: expected "" but got "data:,a"
    226 FAIL "data:,a 1w  1h" (leading U+2005) assert_equals: expected "" but got "data:,a"
    227 FAIL "data:,a 1w  1h" (leading U+2006) assert_equals: expected "" but got "data:,a"
    228 FAIL "data:,a 1w  1h" (leading U+2007) assert_equals: expected "" but got "data:,a"
    229 FAIL "data:,a 1w  1h" (leading U+2008) assert_equals: expected "" but got "data:,a"
    230 FAIL "data:,a 1w  1h" (leading U+2009) assert_equals: expected "" but got "data:,a"
    231 FAIL "data:,a 1w  1h" (leading U+200A) assert_equals: expected "" but got "data:,a"
     220PASS "data:,a 1w  1h" (leading U+1680)
     221PASS "data:,a 1w  1h" (leading U+2000)
     222PASS "data:,a 1w  1h" (leading U+2001)
     223PASS "data:,a 1w  1h" (leading U+2002)
     224PASS "data:,a 1w  1h" (leading U+2003)
     225PASS "data:,a 1w  1h" (leading U+2004)
     226PASS "data:,a 1w  1h" (leading U+2005)
     227PASS "data:,a 1w  1h" (leading U+2006)
     228PASS "data:,a 1w  1h" (leading U+2007)
     229PASS "data:,a 1w  1h" (leading U+2008)
     230PASS "data:,a 1w  1h" (leading U+2009)
     231PASS "data:,a 1w  1h" (leading U+200A)
    232232PASS "data:,a 1w ‌1h" (leading U+200C)
    233233PASS "data:,a 1w ‍1h" (leading U+200D)
    234234PASS "data:,a 1w  1h" (leading U+202F)
    235 FAIL "data:,a 1w  1h" (leading U+205F) assert_equals: expected "" but got "data:,a"
    236 FAIL "data:,a 1w  1h" (leading U+3000) assert_equals: expected "" but got "data:,a"
     235PASS "data:,a 1w  1h" (leading U+205F)
     236PASS "data:,a 1w  1h" (leading U+3000)
    237237PASS "data:,a 1w 1h" (leading U+FEFF)
    238238                                                                                                                                                                                                                                             
  • trunk/Source/WebCore/ChangeLog

    r205512 r205515  
     12016-09-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Align srcset attribute parsing with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=161636
     5
     6        Reviewed by Darin Adler.
     7
     8        Align srcset attribute parsing with the HTML specification:
     9        - https://html.spec.whatwg.org/#parse-a-srcset-attribute
     10
     11        The new behavior is also consistent with Firefox and Chrome
     12        as all 3 browsers now pass 100% of the checks at:
     13        - http://w3c-test.org/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html
     14
     15        No new tests, rebaselined existing tests.
     16
     17        * html/parser/HTMLParserIdioms.cpp:
     18        (WebCore::parseValidHTMLNonNegativeIntegerInternal):
     19        (WebCore::parseValidHTMLNonNegativeInteger):
     20        (WebCore::parseValidHTMLFloatingPointNumberInternal):
     21        (WebCore::parseValidHTMLFloatingPointNumber):
     22        * html/parser/HTMLParserIdioms.h:
     23        Add convenience for parsing *valid* HTML non-negative integers and
     24        *valid* floating point number values.
     25
     26        * html/parser/HTMLSrcsetParser.cpp:
     27        (WebCore::parseDescriptors):
     28        - Use parseValidHTMLFloatingPointNumber() to parse density so that the value
     29          is parsed as a valid HTML floating point number value, as per the spec.
     30        - Use parseValidHTMLNonNegativeInteger() to parse width and height so that
     31          the value is parsed as a valid HTML non-negative integer value, as per the
     32          spec.
     33        - Return false if descriptor does not have a h, w and x at the end as per:
     34          https://html.spec.whatwg.org/#parse-a-srcset-attribute (step 13: Anything else)
     35        - Return false if height is set but not width, as per:
     36          https://html.spec.whatwg.org/#parse-a-srcset-attribute (step 14)
     37
     38        (WebCore::parseImageCandidatesFromSrcsetAttribute):
     39        - Skip whitespace if URL does not end with a comma instead of assuming there is
     40          a single space character, as per:
     41          https://html.spec.whatwg.org/#parse-a-srcset-attribute (step 8. Otherwise 1.)
     42
    1432016-09-06  Fujii Hironori  <Hironori.Fujii@sony.com>
    244
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp

    r205400 r205515  
    217217}
    218218
     219template <typename CharacterType>
     220static Optional<int> parseValidHTMLNonNegativeIntegerInternal(const CharacterType* position, const CharacterType* end)
     221{
     222    // A string is a valid non-negative integer if it consists of one or more ASCII digits.
     223    for (auto* c = position; c < end; ++c) {
     224        if (!isASCIIDigit(*c))
     225            return Nullopt;
     226    }
     227
     228    Optional<int> signedValue = parseHTMLIntegerInternal(position, end);
     229    if (!signedValue || signedValue.value() < 0)
     230        return Nullopt;
     231
     232    return signedValue;
     233}
     234
     235// https://html.spec.whatwg.org/#valid-non-negative-integer
     236Optional<int> parseValidHTMLNonNegativeInteger(StringView input)
     237{
     238    if (input.isEmpty())
     239        return Nullopt;
     240
     241    if (LIKELY(input.is8Bit())) {
     242        auto* start = input.characters8();
     243        return parseValidHTMLNonNegativeIntegerInternal(start, start + input.length());
     244    }
     245
     246    auto* start = input.characters16();
     247    return parseValidHTMLNonNegativeIntegerInternal(start, start + input.length());
     248}
     249
     250template <typename CharacterType>
     251static Optional<double> parseValidHTMLFloatingPointNumberInternal(const CharacterType* position, size_t length)
     252{
     253    ASSERT(length > 0);
     254
     255    // parseDouble() allows the string to start with a '+' or to end with a '.' but those
     256    // are not valid floating point numbers as per HTML.
     257    if (*position == '+' || *(position + length - 1) == '.')
     258        return Nullopt;
     259
     260    size_t parsedLength = 0;
     261    double number = parseDouble(position, length, parsedLength);
     262    return parsedLength == length && std::isfinite(number) ? number : Optional<double>();
     263}
     264
     265// https://html.spec.whatwg.org/#valid-floating-point-number
     266Optional<double> parseValidHTMLFloatingPointNumber(StringView input)
     267{
     268    if (input.isEmpty())
     269        return Nullopt;
     270
     271    if (LIKELY(input.is8Bit())) {
     272        auto* start = input.characters8();
     273        return parseValidHTMLFloatingPointNumberInternal(start, input.length());
     274    }
     275
     276    auto* start = input.characters16();
     277    return parseValidHTMLFloatingPointNumberInternal(start, input.length());
     278}
     279
    219280static inline bool isHTMLSpaceOrDelimiter(UChar character)
    220281{
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.h

    r205400 r205515  
    6767// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
    6868WEBCORE_EXPORT Optional<int> parseHTMLNonNegativeInteger(const String&);
     69
     70// https://html.spec.whatwg.org/#valid-non-negative-integer
     71Optional<int> parseValidHTMLNonNegativeInteger(StringView);
     72
     73// https://html.spec.whatwg.org/#valid-floating-point-number
     74Optional<double> parseValidHTMLFloatingPointNumber(StringView);
    6975
    7076// https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-floating-point-number-values
  • trunk/Source/WebCore/html/parser/HTMLSrcsetParser.cpp

    r184040 r205515  
    132132        UChar descriptorChar = descriptor[descriptorCharPosition];
    133133        descriptor = descriptor.substring(0, descriptorCharPosition);
    134         bool isValid = false;
    135134        if (descriptorChar == 'x') {
    136135            if (result.hasDensity() || result.hasHeight() || result.hasWidth())
    137136                return false;
    138             float density = descriptor.toFloat(isValid);
    139             if (!isValid || density < 0)
    140                 return false;
    141             result.setDensity(density);
     137            Optional<double> density = parseValidHTMLFloatingPointNumber(descriptor);
     138            if (!density || density.value() < 0)
     139                return false;
     140            result.setDensity(density.value());
    142141        } else if (descriptorChar == 'w') {
    143142            if (result.hasDensity() || result.hasWidth())
    144143                return false;
    145             int resourceWidth = descriptor.toInt(isValid);
    146             if (!isValid || resourceWidth <= 0)
    147                 return false;
    148             result.setResourceWidth(resourceWidth);
     144            Optional<int> resourceWidth = parseValidHTMLNonNegativeInteger(descriptor);
     145            if (!resourceWidth || resourceWidth.value() <= 0)
     146                return false;
     147            result.setResourceWidth(resourceWidth.value());
    149148        } else if (descriptorChar == 'h') {
    150149            // This is here only for future compat purposes.
     
    152151            if (result.hasDensity() || result.hasHeight())
    153152                return false;
    154             int resourceHeight = descriptor.toInt(isValid);
    155             if (!isValid || resourceHeight <= 0)
    156                 return false;
    157             result.setResourceHeight(resourceHeight);
    158         }
    159     }
    160     return true;
     153            Optional<int> resourceHeight = parseValidHTMLNonNegativeInteger(descriptor);
     154            if (!resourceHeight || resourceHeight.value() <= 0)
     155                return false;
     156            result.setResourceHeight(resourceHeight.value());
     157        } else
     158            return false;
     159    }
     160    return !result.hasHeight() || result.hasWidth();
    161161}
    162162
     
    194194                continue;
    195195        } else {
    196             // Advancing position here (contrary to spec) to avoid an useless extra state machine step.
    197             // Filed a spec bug: https://github.com/ResponsiveImagesCG/picture-element/issues/189
    198             ++position;
     196            skipWhile<CharType, isHTMLSpace<CharType>>(position, attributeEnd);
    199197            Vector<StringView> descriptorTokens;
    200198            tokenizeDescriptors(position, attributeEnd, descriptorTokens);
Note: See TracChangeset for help on using the changeset viewer.