⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267730 in webkit


Ignore:
Timestamp:
Sep 29, 2020, 12:44:40 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Data URL image is not rendered if there is whitespace between the mime type and and "base64" string
https://bugs.webkit.org/show_bug.cgi?id=216900

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2020-09-29
Reviewed by Darin Adler.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/data-urls/processing.any-expected.txt:
  • web-platform-tests/fetch/data-urls/processing.any.worker-expected.txt:

Source/WebCore:

According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs,
spaces are allowed in the data URL to allow better formatting. This
means spaces may appear before and after the comma and the semicolon
(if it exits in the Data URL).

Test: fast/images/image-data-url-with-spaces.html

  • platform/network/DataURLDecoder.cpp:

(WebCore::DataURLDecoder::DecodeTask::process):

LayoutTests:

In the new test, 16 cases are included to cover all the permutations of
adding spaces before and after the comma and the semicolon. PNG and JPEG
formats are used to ensure the mime type is tested.

  • fast/images/image-data-url-with-spaces-expected.html: Added.
  • fast/images/image-data-url-with-spaces.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r267724 r267730  
     12020-09-29  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Data URL image is not rendered if there is whitespace between the mime type and and "base64" string
     4        https://bugs.webkit.org/show_bug.cgi?id=216900
     5
     6        Reviewed by Darin Adler.
     7
     8        In the new test, 16 cases are included to cover all the permutations of
     9        adding spaces before and after the comma and the semicolon. PNG and JPEG
     10        formats are used to ensure the mime type is tested.
     11
     12        * fast/images/image-data-url-with-spaces-expected.html: Added.
     13        * fast/images/image-data-url-with-spaces.html: Added.
     14
    1152020-09-28  Tetsuharu Ohzeki  <tetsuharu.ohzeki@gmail.com>
    216
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r267702 r267730  
     12020-09-29  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Data URL image is not rendered if there is whitespace between the mime type and and "base64" string
     4        https://bugs.webkit.org/show_bug.cgi?id=216900
     5
     6        Reviewed by Darin Adler.
     7
     8        * web-platform-tests/fetch/data-urls/processing.any-expected.txt:
     9        * web-platform-tests/fetch/data-urls/processing.any.worker-expected.txt:
     10
    1112020-09-28  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/processing.any-expected.txt

    r267651 r267730  
    5353PASS "data:x;base64;x,WA"
    5454PASS "data:x;base64=x,WA"
    55 FAIL "data:; base64,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
    56 FAIL "data:;  base64,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
    57 FAIL "data:  ;charset=x   ;  base64,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
     55PASS "data:; base64,WA"
     56PASS "data:;  base64,WA"
     57PASS "data:  ;charset=x   ;  base64,WA"
    5858PASS "data:;base64;,WA"
    59 FAIL "data:;base64 ,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
    60 FAIL "data:;base64   ,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
     59PASS "data:;base64 ,WA"
     60PASS "data:;base64   ,WA"
    6161PASS "data:;base 64,WA"
    6262PASS "data:;BASe64,WA"
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/processing.any.worker-expected.txt

    r267651 r267730  
    5353PASS "data:x;base64;x,WA"
    5454PASS "data:x;base64=x,WA"
    55 FAIL "data:; base64,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
    56 FAIL "data:;  base64,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
    57 FAIL "data:  ;charset=x   ;  base64,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
     55PASS "data:; base64,WA"
     56PASS "data:;  base64,WA"
     57PASS "data:  ;charset=x   ;  base64,WA"
    5858PASS "data:;base64;,WA"
    59 FAIL "data:;base64 ,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
    60 FAIL "data:;base64   ,WA" assert_array_equals: lengths differ, expected array [88] length 1, got object "87,65" length 2
     59PASS "data:;base64 ,WA"
     60PASS "data:;base64   ,WA"
    6161PASS "data:;base 64,WA"
    6262PASS "data:;BASe64,WA"
  • trunk/Source/WebCore/ChangeLog

    r267727 r267730  
     12020-09-29  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Data URL image is not rendered if there is whitespace between the mime type and and "base64" string
     4        https://bugs.webkit.org/show_bug.cgi?id=216900
     5
     6        Reviewed by Darin Adler.
     7
     8        According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs,
     9        spaces are allowed in the data URL to allow better formatting. This
     10        means spaces may appear before and after the comma and the semicolon
     11        (if it exits in the Data URL).
     12
     13        Test: fast/images/image-data-url-with-spaces.html
     14
     15        * platform/network/DataURLDecoder.cpp:
     16        (WebCore::DataURLDecoder::DecodeTask::process):
     17
    1182020-09-28  Yusuke Suzuki  <ysuzuki@apple.com>
    219
  • trunk/Source/WebCore/platform/network/DataURLDecoder.cpp

    r264586 r267730  
    6767    bool process()
    6868    {
     69        // Syntax:
     70        //  url := data:<header>,<encodedData>
     71        //  header := [<mediatype>][;base64]
     72        //  mediatype := [<mimetype>][;charset=<charsettype>]
     73
    6974        if (urlString.find(',') == notFound)
    7075            return false;
     76
    7177        const char dataString[] = "data:";
    72         const char base64String[] = ";base64";
    73 
    7478        ASSERT(urlString.startsWith(dataString));
    7579
    76         size_t headerEnd = urlString.find(',', strlen(dataString));
     80        size_t headerStart = strlen(dataString);
     81        size_t headerEnd = urlString.find(',', headerStart);
    7782        size_t encodedDataStart = headerEnd == notFound ? headerEnd : headerEnd + 1;
    7883
    7984        encodedData = StringView(urlString).substring(encodedDataStart);
    80         auto header = StringView(urlString).substring(strlen(dataString), headerEnd - strlen(dataString));
    81         isBase64 = header.endsWithIgnoringASCIICase(StringView(base64String));
    82         auto mediaType = (isBase64 ? header.substring(0, header.length() - strlen(base64String)) : header).toString();
    83         mediaType = mediaType.stripWhiteSpace();
     85        auto header = StringView(urlString).substring(headerStart, headerEnd - headerStart);
     86       
     87        // There might one or two semicolons in the header, find the last one.
     88        size_t mediaTypeEnd = header.reverseFind(';');
     89        mediaTypeEnd = mediaTypeEnd == notFound ? header.length() : mediaTypeEnd;
     90
     91        // formatTypeStart might be at the begining of "base64" or "charset=...".
     92        size_t formatTypeStart = mediaTypeEnd + 1;
     93        auto formatType = header.substring(formatTypeStart, header.length() - formatTypeStart);
     94        formatType = stripLeadingAndTrailingHTTPSpaces(formatType);
     95
     96        isBase64 = equalLettersIgnoringASCIICase(formatType, "base64");
     97
     98        // If header does not end with "base64", mediaType should be the whole header.
     99        auto mediaType = (isBase64 ? header.substring(0, mediaTypeEnd) : header).toString();
     100        mediaType = stripLeadingAndTrailingHTTPSpaces(mediaType);
    84101        if (mediaType.startsWith(';'))
    85102            mediaType.insert("text/plain", 0);
     103
    86104        result = parseMediaType(mediaType);
    87 
    88105        return true;
    89106    }
Note: See TracChangeset for help on using the changeset viewer.