Changeset 271734 in webkit


Ignore:
Timestamp:
Jan 21, 2021 7:39:46 PM (18 months ago)
Author:
Devin Rousso
Message:

[Payment Request] constructor should throw if a payment method is provided more than once
https://bugs.webkit.org/show_bug.cgi?id=220824

Reviewed by Andy Estes.

LayoutTests/imported/w3c:

  • web-platform-tests/payment-request/payment-request-constructor-thcrash.https-expected.txt:
  • web-platform-tests/payment-request/payment-request-constructor.https.sub-expected.txt:

Source/WebCore:

Test: web-platform-tests/payment-request/payment-request-constructor.https.sub.html

  • Modules/paymentrequest/PaymentRequest.cpp:

(WebCore::stringify): Added.
(WebCore::PaymentRequest::create):

Location:
trunk
Files:
5 edited

Legend:

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

    r271712 r271734  
     12021-01-21  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] constructor should throw if a payment method is provided more than once
     4        https://bugs.webkit.org/show_bug.cgi?id=220824
     5
     6        Reviewed by Andy Estes.
     7
     8        * web-platform-tests/payment-request/payment-request-constructor-thcrash.https-expected.txt:
     9        * web-platform-tests/payment-request/payment-request-constructor.https.sub-expected.txt:
     10
    1112021-01-21  Sam Weinig  <weinig@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-constructor-thcrash.https-expected.txt

    r267647 r271734  
    11
    2 PASS Don't crash if there is an abusive number of payment methods in the methodData sequence
     2FAIL Don't crash if there is an abusive number of payment methods in the methodData sequence assert_equals: must be a TypeError expected "TypeError" but got "RangeError"
    33PASS Don't crash if PaymentMethodData.supportedMethods is an abusive length
    44PASS Don't crash if the request id has an abusive length
  • trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-constructor.https.sub-expected.txt

    r267647 r271734  
    66PASS Use provided request ID
    77PASS If the length of the methodData sequence is zero, then throw a TypeError
    8 FAIL If payment method is duplicate, then throw a RangeError assert_throws_js: function "() => new PaymentRequest(duplicateMethods, defaultDetails)" did not throw
     8PASS If payment method is duplicate, then throw a RangeError
    99PASS Modifier method data must be JSON-serializable object
    1010PASS Rethrow any exceptions of JSON-serializing paymentMethod.data into a string
  • trunk/Source/WebCore/ChangeLog

    r271733 r271734  
     12021-01-21  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] constructor should throw if a payment method is provided more than once
     4        https://bugs.webkit.org/show_bug.cgi?id=220824
     5
     6        Reviewed by Andy Estes.
     7
     8        Test: web-platform-tests/payment-request/payment-request-constructor.https.sub.html
     9
     10        * Modules/paymentrequest/PaymentRequest.cpp:
     11        (WebCore::stringify): Added.
     12        (WebCore::PaymentRequest::create):
     13
    1142021-01-21  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp

    r271703 r271734  
    323323}
    324324
     325static String stringify(const PaymentRequest::MethodIdentifier& identifier)
     326{
     327    return WTF::switchOn(identifier,
     328        [] (const String& string) { return string; },
     329        [] (const URL& url) { return url.string(); }
     330    );
     331}
     332
    325333// Implements the PaymentRequest Constructor
    326334// https://www.w3.org/TR/payment-request/#constructor
     
    339347    Vector<Method> serializedMethodData;
    340348    serializedMethodData.reserveInitialCapacity(methodData.size());
     349    HashSet<String> seenMethodIDs;
    341350    for (auto& paymentMethod : methodData) {
    342351        auto identifier = convertAndValidatePaymentMethodIdentifier(paymentMethod.supportedMethods);
    343352        if (!identifier)
    344353            return Exception { RangeError, makeString('"', paymentMethod.supportedMethods, "\" is an invalid payment method identifier.") };
     354
     355        if (!seenMethodIDs.add(stringify(*identifier)))
     356            return Exception { RangeError, "Payment method IDs must be unique."_s };
    345357
    346358        String serializedData;
Note: See TracChangeset for help on using the changeset viewer.