From aaeaeba4ee2165d68f97fd67a81e8f78a1576826 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 19 Jan 2019 23:02:07 -0500 Subject: [PATCH] add support for attr prefixing on custom field names --- jslib | 2 +- src/services/autofill.service.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/jslib b/jslib index fa65b5637b..50d242e53a 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit fa65b5637b5cd2e93b5d886584d6876c2c5eb571 +Subproject commit 50d242e53a4b553a6cb3575945a84812eda75b1d diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index cf97bc54e3..f14f4b8809 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -870,6 +870,24 @@ export default class AutofillService implements AutofillServiceInterface { private findMatchingFieldIndex(field: AutofillField, names: string[]): number { for (let i = 0; i < names.length; i++) { + if (names[i].indexOf('=') > -1) { + if (this.fieldPropertyIsPrefixMatch(field, 'htmlID', names[i], 'id')) { + return i; + } + if (this.fieldPropertyIsPrefixMatch(field, 'htmlName', names[i], 'name')) { + return i; + } + if (this.fieldPropertyIsPrefixMatch(field, 'label-tag', names[i], 'label')) { + return i; + } + if (this.fieldPropertyIsPrefixMatch(field, 'label-aria', names[i], 'label')) { + return i; + } + if (this.fieldPropertyIsPrefixMatch(field, 'placeholder', names[i], 'placeholder')) { + return i; + } + } + if (this.fieldPropertyIsMatch(field, 'htmlID', names[i])) { return i; } @@ -890,6 +908,16 @@ export default class AutofillService implements AutofillServiceInterface { return -1; } + private fieldPropertyIsPrefixMatch(field: any, property: string, name: string, prefix: string, + separator = '='): boolean { + if (name.indexOf(prefix + separator) === 0) { + const sepIndex = name.indexOf(separator); + const val = name.substring(sepIndex + 1); + return val != null && this.fieldPropertyIsMatch(field, property, val); + } + return false; + } + private fieldPropertyIsMatch(field: any, property: string, name: string): boolean { let fieldVal = field[property] as string; if (!this.hasValue(fieldVal)) {