Closed
Bug 1371145
Opened 9 years ago
Closed 8 years ago
[Form Autofill] Properly fill cc-exp/cc-exp-month/cc-exp-year into a select element
Categories
(Toolkit :: Form Manager, enhancement)
Toolkit
Form Manager
Tracking
()
RESOLVED
FIXED
mozilla57
| Tracking | Status | |
|---|---|---|
| firefox57 | --- | fixed |
People
(Reporter: lchang, Assigned: selee)
References
(Blocks 1 open bug)
Details
(Whiteboard: [form autofill:M4][ETA:8/10])
Attachments
(1 file)
People usually use <select> elements to implement "cc-exp/cc-exp-month/cc-exp-year" fields in practice so we need to handle inexact matches here.
| Assignee | ||
Updated•8 years ago
|
Assignee: nobody → selee
| Assignee | ||
Updated•8 years ago
|
Whiteboard: [form autofill:M4] → [form autofill:M4][ETA:8/10]
| Comment hidden (mozreview-request) |
| Reporter | ||
Comment 2•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8896803 [details]
Bug 1371145 - Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing.
https://reviewboard.mozilla.org/r/168092/#review173268
Are you going to handle months without numbers? BTW, do you think if we need to handle `cc-exp` that uses "01/25" or "0125"?
::: browser/extensions/formautofill/FormAutofillHandler.jsm:223
(Diff revision 1)
> + if (!("cc-exp" in profile) && ("cc-exp-month" in profile) && ("cc-exp-year" in profile)) {
> + fieldNames.push("cc-exp");
> + }
To align with others, I would prefer to compute `cc-exp` in `ProfileStorage` (in `CreditCards._computeFields()`).
::: browser/extensions/formautofill/FormAutofillUtils.jsm:369
(Diff revision 1)
> },
>
> + findCreditCardSelectOption(selectEl, creditCard, fieldName) {
> + let oneDigitMonth = parseInt(creditCard["cc-exp-month"], 10).toString();
> + let twoDigitsMonth = oneDigitMonth.length < 2 ? "0" + oneDigitMonth : oneDigitMonth;
> + let expYearInt = parseInt(creditCard["cc-exp-year"], 10);
`cc-exp-year` will be normalized to 4 digits in storage upon saving so you should treat it as 4 digits here.
::: browser/extensions/formautofill/FormAutofillUtils.jsm:378
(Diff revision 1)
> +
> + switch (fieldName) {
> + case "cc-exp-month": {
> + for (let pattern of [twoDigitsMonth, oneDigitMonth]) {
> + let matchedOption = options.find(o => {
> + return [o.text, o.label, o.value].some(s => s.startsWith(pattern));
`startsWith` isn't accurate as it matches "1" with "12".
::: browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js:21
(Diff revision 1)
> "country": "US",
> };
>
> +const DEFAULT_CREDITCARD_RECORD = {
> + "guid": "123",
> + "cc-exp-month": "09",
No leading zero.
::: browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js:22
(Diff revision 1)
> };
>
> +const DEFAULT_CREDITCARD_RECORD = {
> + "guid": "123",
> + "cc-exp-month": "09",
> + "cc-exp-year": "25",
It is expected to be 4 digits.
::: browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js:297
(Diff revision 1)
> + "cc-exp-month": "option-cc-exp-month-09",
> + "cc-exp-year": "option-cc-exp-year-25",
> + }],
> + },
> + {
> + description: "Credit Card form with matching options which contain labels",
Not sure your purpose of this task since it should pass without `label`, right?
Attachment #8896803 -
Flags: review?(lchang)
| Reporter | ||
Comment 3•8 years ago
|
||
(In reply to Luke Chang [:lchang] from comment #2)
> ::: browser/extensions/formautofill/FormAutofillHandler.jsm:223
> (Diff revision 1)
> > + if (!("cc-exp" in profile) && ("cc-exp-month" in profile) && ("cc-exp-year" in profile)) {
> > + fieldNames.push("cc-exp");
> > + }
>
> To align with others, I would prefer to compute `cc-exp` in `ProfileStorage`
> (in `CreditCards._computeFields()`).
Also, you need to address the normalization of `cc-exp` (split it into `cc-exp-month` and `cc-exp-year`) upon saving.
| Assignee | ||
Comment 4•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8896803 [details]
Bug 1371145 - Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing.
https://reviewboard.mozilla.org/r/168092/#review173268
> To align with others, I would prefer to compute `cc-exp` in `ProfileStorage` (in `CreditCards._computeFields()`).
I would like to do this here because the cc-exp format really depends on the web sites. That means the calcuated result is useless for another web sites.
Even we only support this format: 12/2025 currently, it's still possible to handle the other cases (e.g. 12/25, 12-25, 12-2025) for other sites.
> `startsWith` isn't accurate as it matches "1" with "12".
This won't happen if we compare twoDigitsMonth first then oneDigitMonth.
> Not sure your purpose of this task since it should pass without `label`, right?
hmm, I agree. I copied this case from `third_party/HomeDepot/Checkout_ShippingPayment.html`, and I will refine it to make the coverage more clear.
| Assignee | ||
Comment 5•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8896803 [details]
Bug 1371145 - Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing.
https://reviewboard.mozilla.org/r/168092/#review173268
> This won't happen if we compare twoDigitsMonth first then oneDigitMonth.
I use another approach to handle this issue.
The strings from `<option>` can be parsed then compare to the month value in integer.
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Reporter | ||
Comment 8•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8896803 [details]
Bug 1371145 - Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing.
https://reviewboard.mozilla.org/r/168092/#review173268
> I would like to do this here because the cc-exp format really depends on the web sites. That means the calcuated result is useless for another web sites.
> Even we only support this format: 12/2025 currently, it's still possible to handle the other cases (e.g. 12/25, 12-25, 12-2025) for other sites.
You're right about this matching function. Though what I was saying is that we should have an entry of "cc-exp" in profile directly rather than appending it here. Otherwise, we need to append it everytime when we need `Object.keys(profile)`.
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Reporter | ||
Comment 12•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8896803 [details]
Bug 1371145 - Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing.
https://reviewboard.mozilla.org/r/168092/#review175704
::: browser/extensions/formautofill/FormAutofillUtils.jsm:368
(Diff revision 6)
> return null;
> },
>
> + findCreditCardSelectOption(selectEl, creditCard, fieldName) {
> + let expMonthInt = parseInt(creditCard["cc-exp-month"], 10);
> + let oneDigitMonth = expMonthInt.toString();
nit: `creditCard["cc-exp-month"]` is one-digit format already.
::: browser/extensions/formautofill/FormAutofillUtils.jsm:369
(Diff revision 6)
> },
>
> + findCreditCardSelectOption(selectEl, creditCard, fieldName) {
> + let expMonthInt = parseInt(creditCard["cc-exp-month"], 10);
> + let oneDigitMonth = expMonthInt.toString();
> + let twoDigitsMonth = oneDigitMonth.length < 2 ? "0" + oneDigitMonth : oneDigitMonth;
nit: `oneDigitMonth.padStart(2, "0")`
::: browser/extensions/formautofill/FormAutofillUtils.jsm:371
(Diff revision 6)
> + findCreditCardSelectOption(selectEl, creditCard, fieldName) {
> + let expMonthInt = parseInt(creditCard["cc-exp-month"], 10);
> + let oneDigitMonth = expMonthInt.toString();
> + let twoDigitsMonth = oneDigitMonth.length < 2 ? "0" + oneDigitMonth : oneDigitMonth;
> + let expYearInt = parseInt(creditCard["cc-exp-year"], 10);
> + let twoDigitsYear = (expYearInt - 2000).toString();
Although it's unlikely to happen in the near future, I prefer using `.substr(2, 2)` instead of the magic number "2000".
::: browser/extensions/formautofill/FormAutofillUtils.jsm:379
(Diff revision 6)
> +
> + switch (fieldName) {
> + case "cc-exp-month": {
> + for (let option of options) {
> + if ([option.text, option.label, option.value].some(
> + s => parseInt(s, 10) == expMonthInt
Recommend using `/\d+/` so we can handle "Sep-09" well.
Moreover, I would write like this:
```js
let result = /[1-9]\d*/.exec(s);
return result && result[0] == oneDigitMonth;
```
(And you no longer need `expMonthInt`.)
::: browser/extensions/formautofill/FormAutofillUtils.jsm:397
(Diff revision 6)
> + let patterns = [
> + oneDigitMonth + "/" + twoDigitsYear, // 8/22
> + oneDigitMonth + "/" + fourDigitsYear, // 8/2022
> + twoDigitsMonth + "/" + twoDigitsYear, // 08/22
> + twoDigitsMonth + "/" + fourDigitsYear, // 08/2022
> + oneDigitMonth + "-" + twoDigitsYear, // 8-22
> + oneDigitMonth + "-" + fourDigitsYear, // 8-2022
> + twoDigitsMonth + "-" + twoDigitsYear, // 08-22
> + twoDigitsMonth + "-" + fourDigitsYear, // 08-2022
> + twoDigitsYear + "-" + twoDigitsMonth, // 22-08
> + fourDigitsYear + "-" + twoDigitsMonth, // 2022-08
> + fourDigitsYear + "/" + oneDigitMonth, // 2022/8
> + ];
Not sure if "0822" is the case we need to handle as well?
::: browser/extensions/formautofill/FormAutofillUtils.jsm:413
(Diff revision 6)
> + fourDigitsYear + "/" + oneDigitMonth, // 2022/8
> + ];
> +
> + for (let option of options) {
> + if ([option.text, option.label, option.value].some(
> + str => patterns.some(pattern => pattern == str)
Maybe `str.includes(pattern)` would be better?
::: browser/extensions/formautofill/ProfileStorage.jsm:1473
(Diff revision 6)
> creditCard["cc-family-name"] = nameParts.family;
> hasNewComputedFields = true;
> }
>
> + if (!("cc-exp" in creditCard) && "cc-exp-month" in creditCard && "cc-exp-year" in creditCard) {
> + creditCard["cc-exp"] = creditCard["cc-exp-year"] + "-" + creditCard["cc-exp-month"];
A valid month string needs two-digit month number where `cc-exp-month` isn't.
::: browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js:23
(Diff revision 6)
>
> +const DEFAULT_CREDITCARD_RECORD = {
> + "guid": "123",
> + "cc-exp-month": "1",
> + "cc-exp-year": "2025",
> + "cc-exp": "1/2025",
`2025-01`
Attachment #8896803 -
Flags: review?(lchang)
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Reporter | ||
Comment 15•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8896803 [details]
Bug 1371145 - Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing.
https://reviewboard.mozilla.org/r/168092/#review176126
Thanks.
::: browser/extensions/formautofill/FormAutofillUtils.jsm:330
(Diff revision 8)
>
> return null;
> },
>
> + findCreditCardSelectOption(selectEl, creditCard, fieldName) {
> + let oneDigitMonth = creditCard["cc-exp-month"];
`cc-exp-month` is a number so it will fail when calling `padStart` below.
```js
let oneDigitMonth = creditCard["cc-exp-month"].toString();
```
::: browser/extensions/formautofill/FormAutofillUtils.jsm:332
(Diff revision 8)
> + let expYearInt = parseInt(creditCard["cc-exp-year"], 10);
> + let twoDigitsYear = expYearInt.toString().substr(2, 2);
> + let fourDigitsYear = expYearInt.toString();
nit: Not sure if we'll need `expYearInt` eventually but how about:
```js
let fourDigitsYear = creditCard["cc-exp-year"].toString();
let twoDigitsYear = fourDigitsYear.substr(2, 2);
```
::: browser/extensions/formautofill/ProfileStorage.jsm:1475
(Diff revision 8)
> creditCard["cc-family-name"] = nameParts.family;
> hasNewComputedFields = true;
> }
>
> + if (!("cc-exp" in creditCard) && "cc-exp-month" in creditCard && "cc-exp-year" in creditCard) {
> + creditCard["cc-exp"] = creditCard["cc-exp-year"] + "-" + creditCard["cc-exp-month"].toString().padStart(2, "0");
`creditCard["cc-exp-year"].toString()`
::: browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js:21
(Diff revision 8)
> + "cc-exp-month": "1",
> + "cc-exp-year": "2025",
Use number type.
Attachment #8896803 -
Flags: review?(lchang) → review+
| Comment hidden (mozreview-request) |
| Assignee | ||
Comment 17•8 years ago
|
||
| Assignee | ||
Comment 18•8 years ago
|
||
| Comment hidden (mozreview-request) |
| Assignee | ||
Updated•8 years ago
|
Keywords: checkin-needed
Comment 20•8 years ago
|
||
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/f1a379e6da52
Calculate the possible option of cc-exp/cc-exp-year/cc-exp-month for filling and previewing. r=lchang
Keywords: checkin-needed
Comment 21•8 years ago
|
||
| bugherder | ||
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox57:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
You need to log in
before you can comment on or make changes to this bug.
Description
•