1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-19 20:51:35 +01:00

allow csv field names as well

This commit is contained in:
Kyle Spearrin 2017-11-13 14:09:45 -05:00
parent 745b17fe95
commit 907247b3a7

View File

@ -88,7 +88,7 @@ var IsoProvinces: { [id: string]: string; } = {
export default class AutofillService { export default class AutofillService {
constructor(public cipherService: CipherService, public tokenService: TokenService, constructor(public cipherService: CipherService, public tokenService: TokenService,
public totpService: TotpService, public utilsService: UtilsService) { public totpService: TotpService, public utilsService: UtilsService) {
} }
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
@ -288,8 +288,8 @@ export default class AutofillService {
} }
private generateLoginFillScript(fillScript: AutofillScript, pageDetails: any, private generateLoginFillScript(fillScript: AutofillScript, pageDetails: any,
filledFields: { [id: string]: AutofillField; }, filledFields: { [id: string]: AutofillField; },
options: any): AutofillScript { options: any): AutofillScript {
if (!options.cipher.login) { if (!options.cipher.login) {
return null; return null;
} }
@ -399,8 +399,8 @@ export default class AutofillService {
} }
private generateCardFillScript(fillScript: AutofillScript, pageDetails: any, private generateCardFillScript(fillScript: AutofillScript, pageDetails: any,
filledFields: { [id: string]: AutofillField; }, filledFields: { [id: string]: AutofillField; },
options: any): AutofillScript { options: any): AutofillScript {
if (!options.cipher.card) { if (!options.cipher.card) {
return null; return null;
} }
@ -473,8 +473,8 @@ export default class AutofillService {
} }
private generateIdentityFillScript(fillScript: AutofillScript, pageDetails: any, private generateIdentityFillScript(fillScript: AutofillScript, pageDetails: any,
filledFields: { [id: string]: AutofillField; }, filledFields: { [id: string]: AutofillField; },
options: any): AutofillScript { options: any): AutofillScript {
if (!options.cipher.identity) { if (!options.cipher.identity) {
return null; return null;
} }
@ -657,8 +657,8 @@ export default class AutofillService {
} }
private makeScriptAction(fillScript: AutofillScript, cipherData: any, fillFields: any, private makeScriptAction(fillScript: AutofillScript, cipherData: any, fillFields: any,
filledFields: { [id: string]: AutofillField; }, dataProp: string, filledFields: { [id: string]: AutofillField; }, dataProp: string,
fieldProp?: string) { fieldProp?: string) {
fieldProp = fieldProp || dataProp; fieldProp = fieldProp || dataProp;
if (cipherData[dataProp] && cipherData[dataProp] !== '' && fillFields[fieldProp]) { if (cipherData[dataProp] && cipherData[dataProp] !== '' && fillFields[fieldProp]) {
filledFields[fillFields[fieldProp].opid] = fillFields[fieldProp]; filledFields[fillFields[fieldProp].opid] = fillFields[fieldProp];
@ -679,7 +679,7 @@ export default class AutofillService {
} }
private findUsernameField(pageDetails: AutofillPageDetails, passwordField: AutofillField, canBeHidden: boolean, private findUsernameField(pageDetails: AutofillPageDetails, passwordField: AutofillField, canBeHidden: boolean,
withoutForm: boolean) { withoutForm: boolean) {
let usernameField: AutofillField = null; let usernameField: AutofillField = null;
for (const f of pageDetails.fields) { for (const f of pageDetails.fields) {
if (f.elementNumber >= passwordField.elementNumber) { if (f.elementNumber >= passwordField.elementNumber) {
@ -725,15 +725,26 @@ export default class AutofillService {
return false; return false;
} }
fieldVal = fieldVal.replace(/(?:\r\n|\r|\n)/g, ''); fieldVal = fieldVal.trim().replace(/(?:\r\n|\r|\n)/g, '');
if (name.startsWith('regex:')) { if (name.startsWith('regex=')) {
try { try {
const regexParts = name.split(':', 2); const regexParts = name.split('=', 2);
if (regexParts.length === 2) { if (regexParts.length === 2) {
const regex = new RegExp(regexParts[1], 'i'); const regex = new RegExp(regexParts[1], 'i');
return regex.test(fieldVal); return regex.test(fieldVal);
} }
} catch (e) { } } catch (e) { }
} else if (name.startsWith('csv=')) {
const csvParts = name.split('=', 2);
if (csvParts.length === 2) {
const csvVals = csvParts[1].split(',');
for (const val of csvVals) {
if (val != null && val.trim().toLowerCase() === fieldVal.toLowerCase()) {
return true;
}
}
return false;
}
} }
return fieldVal.toLowerCase() === name; return fieldVal.toLowerCase() === name;
@ -773,7 +784,7 @@ export default class AutofillService {
} }
private setFillScriptForFocus(filledFields: { [id: string]: AutofillField; }, private setFillScriptForFocus(filledFields: { [id: string]: AutofillField; },
fillScript: AutofillScript): AutofillScript { fillScript: AutofillScript): AutofillScript {
let lastField: AutofillField = null; let lastField: AutofillField = null;
let lastPasswordField: AutofillField = null; let lastPasswordField: AutofillField = null;