Changeset 280046 in webkit


Ignore:
Timestamp:
Jul 19, 2021 2:33:16 PM (12 months ago)
Author:
Chris Dumez
Message:

FetchResponse.formData() should not reject promise if the body is null and the MIME Type is "application/x-www-form-urlencoded"
https://bugs.webkit.org/show_bug.cgi?id=228085

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT tests now that more checks are passing.

  • web-platform-tests/fetch/api/request/request-consume-empty.any-expected.txt:
  • web-platform-tests/fetch/api/request/request-consume-empty.any.worker-expected.txt:
  • web-platform-tests/fetch/api/response/response-consume-empty.any-expected.txt:
  • web-platform-tests/fetch/api/response/response-consume-empty.any.worker-expected.txt:

Source/WebCore:

FetchResponse.formData() should not reject promise if the body is null and the MIME Type is "application/x-www-form-urlencoded":

As per the specification, we should package an empty byte sequence in this case and resolve the promise with that.

No new tests, rebaselined existing tests.

  • Modules/fetch/FetchBodyConsumer.cpp:

(WebCore::FetchBodyConsumer::packageFormData):
(WebCore::resolveWithTypeAndData):
(WebCore::packageFormData): Deleted.

  • Modules/fetch/FetchBodyConsumer.h:
  • Modules/fetch/FetchBodyOwner.cpp:

(WebCore::FetchBodyOwner::formData):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r280044 r280046  
     12021-07-19  Chris Dumez  <cdumez@apple.com>
     2
     3        FetchResponse.formData() should not reject promise if the body is null and the MIME Type is "application/x-www-form-urlencoded"
     4        https://bugs.webkit.org/show_bug.cgi?id=228085
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rebaseline WPT tests now that more checks are passing.
     9
     10        * web-platform-tests/fetch/api/request/request-consume-empty.any-expected.txt:
     11        * web-platform-tests/fetch/api/request/request-consume-empty.any.worker-expected.txt:
     12        * web-platform-tests/fetch/api/response/response-consume-empty.any-expected.txt:
     13        * web-platform-tests/fetch/api/response/response-consume-empty.any.worker-expected.txt:
     14
    1152021-07-19  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.any-expected.txt

    r279969 r280046  
    55PASS Consume request's body as json (error case)
    66PASS Consume request's body as formData with correct multipart type (error case)
    7 FAIL Consume request's body as formData with correct urlencoded type promise_test: Unhandled rejection with value: object "TypeError: Type error"
     7PASS Consume request's body as formData with correct urlencoded type
    88PASS Consume request's body as formData without correct type (error case)
    99PASS Consume empty blob request body as arrayBuffer
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.any.worker-expected.txt

    r279969 r280046  
    55PASS Consume request's body as json (error case)
    66PASS Consume request's body as formData with correct multipart type (error case)
    7 FAIL Consume request's body as formData with correct urlencoded type promise_test: Unhandled rejection with value: object "TypeError: Type error"
     7PASS Consume request's body as formData with correct urlencoded type
    88PASS Consume request's body as formData without correct type (error case)
    99PASS Consume empty blob request body as arrayBuffer
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.any-expected.txt

    r279969 r280046  
    55PASS Consume response's body as json (error case)
    66PASS Consume response's body as formData with correct multipart type (error case)
    7 FAIL Consume response's body as formData with correct urlencoded type promise_test: Unhandled rejection with value: object "TypeError: Type error"
     7PASS Consume response's body as formData with correct urlencoded type
    88PASS Consume response's body as formData without correct type (error case)
    99PASS Consume empty blob response body as arrayBuffer
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.any.worker-expected.txt

    r279969 r280046  
    55PASS Consume response's body as json (error case)
    66PASS Consume response's body as formData with correct multipart type (error case)
    7 FAIL Consume response's body as formData with correct urlencoded type promise_test: Unhandled rejection with value: object "TypeError: Type error"
     7PASS Consume response's body as formData with correct urlencoded type
    88PASS Consume response's body as formData without correct type (error case)
    99PASS Consume empty blob response body as arrayBuffer
  • trunk/Source/WebCore/ChangeLog

    r280024 r280046  
     12021-07-19  Chris Dumez  <cdumez@apple.com>
     2
     3        FetchResponse.formData() should not reject promise if the body is null and the MIME Type is "application/x-www-form-urlencoded"
     4        https://bugs.webkit.org/show_bug.cgi?id=228085
     5
     6        Reviewed by Alex Christensen.
     7
     8        FetchResponse.formData() should not reject promise if the body is null and the MIME Type is "application/x-www-form-urlencoded":
     9        - https://fetch.spec.whatwg.org/#concept-body-consume-body
     10        - https://fetch.spec.whatwg.org/#concept-body-package-data
     11
     12        As per the specification, we should package an empty byte sequence in this case and resolve the promise with that.
     13
     14        No new tests, rebaselined existing tests.
     15
     16        * Modules/fetch/FetchBodyConsumer.cpp:
     17        (WebCore::FetchBodyConsumer::packageFormData):
     18        (WebCore::resolveWithTypeAndData):
     19        (WebCore::packageFormData): Deleted.
     20        * Modules/fetch/FetchBodyConsumer.h:
     21        * Modules/fetch/FetchBodyOwner.cpp:
     22        (WebCore::FetchBodyOwner::formData):
     23
    1242021-07-19  Ziran Sun  <zsun@igalia.com>
    225
  • trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp

    r278714 r280046  
    125125
    126126// https://fetch.spec.whatwg.org/#concept-body-package-data
    127 static RefPtr<DOMFormData> packageFormData(ScriptExecutionContext* context, const String& contentType, const uint8_t* data, size_t length)
     127RefPtr<DOMFormData> FetchBodyConsumer::packageFormData(ScriptExecutionContext* context, const String& contentType, const uint8_t* data, size_t length)
    128128{
    129129    auto parseMultipartPart = [context] (const uint8_t* part, size_t partLength, DOMFormData& form) -> bool {
     
    230230        return;
    231231    case FetchBodyConsumer::Type::FormData:
    232         if (auto formData = packageFormData(context, contentType, data, length))
     232        if (auto formData = FetchBodyConsumer::packageFormData(context, contentType, data, length))
    233233            promise->resolve<IDLInterface<DOMFormData>>(*formData);
    234234        else
  • trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.h

    r278532 r280046  
    3838
    3939class Blob;
     40class DOMFormData;
    4041class FetchBodySource;
    4142class ReadableStream;
     
    7475    void setAsLoading() { m_isLoading = true; }
    7576
     77    static RefPtr<DOMFormData> packageFormData(ScriptExecutionContext*, const String& contentType, const uint8_t* data, size_t length);
     78
    7679private:
    7780    Ref<Blob> takeAsBlob(ScriptExecutionContext*);
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp

    r279969 r280046  
    3535#include "HTTPParsers.h"
    3636#include "JSBlob.h"
     37#include "JSDOMFormData.h"
    3738#include "ResourceError.h"
    3839#include "ResourceResponse.h"
     
    186187    }
    187188
     189    if (isDisturbedOrLocked()) {
     190        promise->reject(Exception { TypeError, "Body is disturbed or locked"_s });
     191        return;
     192    }
     193
    188194    if (isBodyNullOrOpaque()) {
     195        if (isBodyNull()) {
     196            // If the content-type is 'application/x-www-form-urlencoded', a body is not required and we should package an empty byte sequence as per the specification.
     197            if (auto formData = FetchBodyConsumer::packageFormData(promise->scriptExecutionContext(), m_contentType, nullptr, 0)) {
     198                promise->resolve<IDLInterface<DOMFormData>>(*formData);
     199                return;
     200            }
     201        }
     202
    189203        promise->reject(TypeError);
    190204        return;
    191205    }
    192     if (isDisturbedOrLocked()) {
    193         promise->reject(Exception { TypeError, "Body is disturbed or locked"_s });
    194         return;
    195     }
     206
    196207    m_isDisturbed = true;
    197208    m_body->formData(*this, WTFMove(promise));
Note: See TracChangeset for help on using the changeset viewer.