mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
better format card expirations
This commit is contained in:
@@ -437,7 +437,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
fillFields.number = f;
|
fillFields.number = f;
|
||||||
} else if (!fillFields.exp && this.isFieldMatch(f[attr],
|
} else if (!fillFields.exp && this.isFieldMatch(f[attr],
|
||||||
['cc-exp', 'card-exp', 'cc-expiration', 'card-expiration', 'cc-ex', 'card-ex', 'card-expire',
|
['cc-exp', 'card-exp', 'cc-expiration', 'card-expiration', 'cc-ex', 'card-ex', 'card-expire',
|
||||||
'validite', 'expiration'], [])) {
|
'validite', 'expiration', 'mm-yy', 'mm-yyyy', 'yy-mm', 'yyyy-mm'], [])) {
|
||||||
fillFields.exp = f;
|
fillFields.exp = f;
|
||||||
} else if (!fillFields.expMonth && this.isFieldMatch(f[attr],
|
} else if (!fillFields.expMonth && this.isFieldMatch(f[attr],
|
||||||
['exp-month', 'cc-exp-month', 'cc-month', 'card-month', 'cc-mo', 'card-mo', 'exp-mo',
|
['exp-month', 'cc-exp-month', 'cc-month', 'card-month', 'cc-mo', 'card-mo', 'exp-mo',
|
||||||
@@ -497,18 +497,61 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fillFields.exp && this.hasValue(card.expMonth) && this.hasValue(card.expYear)) {
|
if (fillFields.exp && this.hasValue(card.expMonth) && this.hasValue(card.expYear)) {
|
||||||
let year = card.expYear;
|
const fullMonth = ('0' + card.expMonth).slice(-2);
|
||||||
if (year.length === 2) {
|
|
||||||
year = '20' + year;
|
let fullYear: string = card.expYear;
|
||||||
|
let partYear: string = null;
|
||||||
|
if (fullYear.length === 2) {
|
||||||
|
partYear = fullYear;
|
||||||
|
fullYear = '20' + fullYear;
|
||||||
|
} else if (fullYear.length === 4) {
|
||||||
|
partYear = fullYear.substr(2, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
let exp: string;
|
||||||
|
if (this.fieldAttrsContain(fillFields.exp, 'mm/yy') && partYear != null) {
|
||||||
|
exp = fullMonth + '/' + partYear;
|
||||||
|
} else if (this.fieldAttrsContain(fillFields.exp, 'mm/yyyy')) {
|
||||||
|
exp = fullMonth + '/' + fullYear;
|
||||||
|
} else if (this.fieldAttrsContain(fillFields.exp, 'yy/mm') && partYear != null) {
|
||||||
|
exp = partYear + '/' + fullMonth;
|
||||||
|
} else if (this.fieldAttrsContain(fillFields.exp, 'yyyy/mm')) {
|
||||||
|
exp = fullYear + '/' + fullMonth;
|
||||||
|
} else if (this.fieldAttrsContain(fillFields.exp, 'mm-yy') && partYear != null) {
|
||||||
|
exp = fullMonth + '-' + partYear;
|
||||||
|
} else if (this.fieldAttrsContain(fillFields.exp, 'mm-yyyy')) {
|
||||||
|
exp = fullMonth + '-' + fullYear;
|
||||||
|
} else if (this.fieldAttrsContain(fillFields.exp, 'yy-mm') && partYear != null) {
|
||||||
|
exp = partYear + '-' + fullMonth;
|
||||||
|
} else {
|
||||||
|
exp = fullYear + '-' + fullMonth;
|
||||||
}
|
}
|
||||||
|
|
||||||
const exp = year + '-' + ('0' + card.expMonth).slice(-2);
|
|
||||||
this.makeScriptActionWithValue(fillScript, exp, fillFields.exp, filledFields);
|
this.makeScriptActionWithValue(fillScript, exp, fillFields.exp, filledFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fillScript;
|
return fillScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fieldAttrsContain(field: any, containsVal: string) {
|
||||||
|
if (!field) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let doesContain = false;
|
||||||
|
CardAttributes.forEach((attr) => {
|
||||||
|
if (doesContain || !field.hasOwnProperty(attr) || !field[attr]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let val = field[attr];
|
||||||
|
val = val.replace(/ /g, '').toLowerCase();
|
||||||
|
doesContain = val.indexOf(containsVal) > -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return doesContain;
|
||||||
|
}
|
||||||
|
|
||||||
private generateIdentityFillScript(fillScript: AutofillScript, pageDetails: any,
|
private generateIdentityFillScript(fillScript: AutofillScript, pageDetails: any,
|
||||||
filledFields: { [id: string]: AutofillField; }, options: any): AutofillScript {
|
filledFields: { [id: string]: AutofillField; }, options: any): AutofillScript {
|
||||||
if (!options.cipher.identity) {
|
if (!options.cipher.identity) {
|
||||||
|
|||||||
Reference in New Issue
Block a user