[PM-8833] Adjusting field qualification

This commit is contained in:
Cesar Gonzalez 2024-10-09 13:44:43 -05:00
parent f5a0e95461
commit de47d16c4d
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
1 changed files with 32 additions and 9 deletions

View File

@ -37,7 +37,13 @@ export class InlineMenuFieldQualificationService
private autocompleteDisabledValues = new Set(["off", "false"]); private autocompleteDisabledValues = new Set(["off", "false"]);
private newFieldKeywords = new Set(["new", "neue", "ändern"]); private newFieldKeywords = new Set(["new", "neue", "ändern"]);
private accountCreationFieldKeywords = [ private accountCreationFieldKeywords = [
...new Set(["register", "registration", "create", "confirm", ...this.newFieldKeywords]), ...new Set([
"register",
"registration",
"create",
"confirm password",
...this.newFieldKeywords,
]),
]; ];
private updatePasswordFieldKeywords = ["update", "change", "current"]; private updatePasswordFieldKeywords = ["update", "change", "current"];
private creditCardFieldKeywords = [ private creditCardFieldKeywords = [
@ -289,10 +295,22 @@ export class InlineMenuFieldQualificationService
field: AutofillField, field: AutofillField,
pageDetails: AutofillPageDetails, pageDetails: AutofillPageDetails,
): boolean { ): boolean {
const parentForm = pageDetails.forms[field.form];
// If the provided field is set with an autocomplete value of "current-password", we should assume that // If the provided field is set with an autocomplete value of "current-password", we should assume that
// the page developer intends for this field to be interpreted as a password field for a login form. // the page developer intends for this field to be interpreted as a password field for a login form.
if (this.fieldContainsAutocompleteValues(field, this.currentPasswordAutocompleteValue)) { if (this.fieldContainsAutocompleteValues(field, this.currentPasswordAutocompleteValue)) {
return pageDetails.fields.filter(this.isNewPasswordField).length === 0; if (!parentForm) {
return (
pageDetails.fields.filter(this.isNewPasswordField).filter((f) => f.viewable).length === 0
);
}
return (
pageDetails.fields
.filter(this.isNewPasswordField)
.filter((f) => f.viewable && f.form === field.form).length === 0
);
} }
const usernameFieldsInPageDetails = pageDetails.fields.filter(this.isUsernameField); const usernameFieldsInPageDetails = pageDetails.fields.filter(this.isUsernameField);
@ -306,7 +324,6 @@ export class InlineMenuFieldQualificationService
// If the field is not structured within a form, we need to identify if the field is present on // If the field is not structured within a form, we need to identify if the field is present on
// a page with multiple password fields. If that isn't the case, we can assume this is a login form field. // a page with multiple password fields. If that isn't the case, we can assume this is a login form field.
const parentForm = pageDetails.forms[field.form];
if (!parentForm) { if (!parentForm) {
// If no parent form is found, and multiple password fields are present, we should assume that // If no parent form is found, and multiple password fields are present, we should assume that
// the passed field belongs to a user account creation form. // the passed field belongs to a user account creation form.
@ -419,12 +436,18 @@ export class InlineMenuFieldQualificationService
return false; return false;
} }
// If the form that contains the field has more than one visible field, we should assume // If the form that contains a single field, we should assume that it is part
// that the field is part of an account creation form. // of a multistep login form.
const fieldsWithinForm = pageDetails.fields.filter( const fieldsWithinForm = pageDetails.fields.filter(
(pageDetailsField) => pageDetailsField.form === field.form, (pageDetailsField) => pageDetailsField.form === field.form,
); );
return fieldsWithinForm.length === 1; if (fieldsWithinForm.length === 1) {
return true;
}
// If multiple fields exist within the form, we should check if a single visible field exists.
// If so, we should assume that the field is part of a login form.
return fieldsWithinForm.filter((field) => field.viewable).length === 1;
} }
// If a single password field exists within the page details, and that password field is part of // If a single password field exists within the page details, and that password field is part of
@ -442,8 +465,7 @@ export class InlineMenuFieldQualificationService
return false; return false;
} }
// If no visible fields are found on the page, but we have a single password // If we have a single password field we should assume that the field is part of a login form.
// field we should assume that the field is part of a login form.
if (passwordFieldsInPageDetails.length === 1) { if (passwordFieldsInPageDetails.length === 1) {
return true; return true;
} }
@ -817,7 +839,8 @@ export class InlineMenuFieldQualificationService
isUsernameField = (field: AutofillField): boolean => { isUsernameField = (field: AutofillField): boolean => {
if ( if (
!this.usernameFieldTypes.has(field.type) || !this.usernameFieldTypes.has(field.type) ||
this.isExcludedFieldType(field, this.excludedAutofillFieldTypesSet) this.isExcludedFieldType(field, this.excludedAutofillFieldTypesSet) ||
this.keywordsFoundInFieldData(field, AutoFillConstants.FieldIgnoreList)
) { ) {
return false; return false;
} }