New issue
Advanced search Search tips

Issue 647766 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Nov 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

Don’t throw for invalid PaymentCurrencyAmount 'value' field in PaymentRequest API

Reported by sideshowbarker@gmail.com, Sep 16 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2863.0 Safari/537.36

Steps to reproduce the problem:
1.  Open https://sideshowbarker.net/tests/payment-request/invalid-value2.html in a build that has the PaymentRequest API enabled.

What is the expected behavior?
You should see this:

Test passes

The Payment Request API spec does not state what UAs must do if the value field of a PaymentCurrencyAmount is not syntactically valid. Specifically, the spec does not state that the UA must throw.

Called PaymentRequest constructor with value "x" for the value field:

    new PaymentRequest([{supportedMethods: ['foo']}], {total: {label: 'bar', amount: {currency: 'USD', value: 'x'}}})

... and as expected, browser did not throw.

What went wrong?
Instead of the expected behavior I get this:

Test fails

The Payment Request API spec does not state what UAs must do if the value field of a PaymentCurrencyAmount is not syntactically valid. Specifically, the spec does not state that the UA must throw.

Called PaymentRequest constructor with value "x" for the value field:

    new PaymentRequest([{supportedMethods: ['foo']}], {total: {label: 'bar', amount: {currency: 'USD', value: 'x'}}})

Expected browser to not throw, but instead browser threw:

    TypeError: Failed to construct 'PaymentRequest': 'x' is not a valid amount format

Did this work before? N/A 

Chrome version: 55.0.2863.0  Channel: canary
OS Version: OS X 10.11.6
Flash Version: 

The browser should not throw for 'x' or any other non-valid amount format, because the spec does not state any requirement for the browser to throw for that condition.
 
Components: Blink>Payments
Labels: -OS-Mac OS-All
Mac->All
+Blink>Payments
The spec says the value should conform to ^-?[0-9]+(\.[0-9]+)?$ regex. What else could the API do when the value is invalid? I can think of only throwing. If this is is not documented in the spec, but it should be, then let's fix the spec.

From https://w3c.github.io/browser-payment-api/#paymentcurrencyamount :

---------------------------
value

A valid decimal monetary value containing a monetary amount. A string is a valid decimal monetary value if it consists of the following components in the given order:

Optionally, a single U+002D HYPHEN-MINUS character (-), to indicate that the amount is negative
One or more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9)

Optionally, a single U+002E FULL STOP character (.) followed by one or more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9)

NOTE

The following regular expression is an implementation of the above definition.
^-?[0-9]+(\.[0-9]+)?$

---------------------------
After I filed this issues, I subsequently filed a PR against the PaymentRequest spec to explicitly require a TypeError for this case. And Ade merge the PR, which makes the current spec now align with the existing Blink behavior for this case. So I believe this issue can probably now just be closed.
Status: WontFix (was: Unconfirmed)

Sign in to add a comment