commit da030fe8e2ae17de86e2a1418eba8994b1854c0d
parent 83826da275bff397520cc3d327228c18811ddd06
Author: Neil Deakin <neil@mozilla.com>
Date: Tue, 7 Oct 2025 14:00:40 +0000
Bug 1956282, when fathom matches a credit card name, also check if the field matches an address name, r=dimi,credential-management-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D267546
Diffstat:
2 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/browser/extensions/formautofill/test/browser/heuristics/browser_parse_name_fields.js b/browser/extensions/formautofill/test/browser/heuristics/browser_parse_name_fields.js
@@ -238,4 +238,30 @@ add_heuristic_tests([
},
],
},
+ {
+ description: `Form field where fathom detects credit card name`,
+ fixtureData: `
+ <html><body>
+ <label>Nom<input/></label>
+ <label>Prénom<input/></label>
+ <label>Saisir une adresse avec un numéro de maison<input/></label>
+ <label>Ligne d'adresse 2<input/></label>
+ <label>Code postal<input/></label>
+ </body></html>
+ `,
+ expectedResult: [
+ {
+ default: {
+ reason: "regex-heuristic",
+ },
+ fields: [
+ { fieldName: "family-name", reason: "update-heuristic" },
+ { fieldName: "given-name" },
+ { fieldName: "address-line1", reason: "update-heuristic-alternate" },
+ { fieldName: "address-line2", reason: "update-heuristic" },
+ { fieldName: "postal-code" },
+ ],
+ },
+ ],
+ },
]);
diff --git a/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs
@@ -1031,6 +1031,8 @@ export const FormAutofillHeuristics = {
return ["email", inferredInfo];
}
+ let fathomFoundType;
+
if (lazy.FormAutofillUtils.isFathomCreditCardsEnabled()) {
// We don't care fields that are not supported by fathom
const fathomFields = fields.filter(r =>
@@ -1046,7 +1048,13 @@ export const FormAutofillHeuristics = {
}
// At this point, use fathom's recommendation if it has one
if (matchedFieldName) {
- return [matchedFieldName, inferredInfo];
+ // If the name was matched, fall through and try to detect if the
+ // field also matches an address type, which may be a better match.
+ if (matchedFieldName != "cc-name") {
+ return [matchedFieldName, inferredInfo];
+ }
+
+ fathomFoundType == CC_TYPE;
}
// Continue to run regex-based heuristics even when fathom doesn't recognize
@@ -1097,7 +1105,11 @@ export const FormAutofillHeuristics = {
}
// Find a matched field name using regexp-based heuristics
- const matchedFieldNames = this._findMatchedFieldNames(element, fields);
+ const matchedFieldNames = this._findMatchedFieldNames(
+ element,
+ fields,
+ fathomFoundType
+ );
return [matchedFieldNames, inferredInfo];
},
@@ -1299,7 +1311,7 @@ export const FormAutofillHeuristics = {
* @param {Array<string>} fieldNames An array of field names to compare against.
* @returns {Array} An array of the matching field names.
*/
- _findMatchedFieldNames(element, fieldNames) {
+ _findMatchedFieldNames(element, fieldNames, foundType = "") {
if (!fieldNames.length) {
return [];
}
@@ -1310,7 +1322,6 @@ export const FormAutofillHeuristics = {
lazy.FormAutofillUtils.isCreditCardField(name) ? CC_TYPE : ADDR_TYPE,
]);
- let foundType;
let attribute = true;
let matchedFieldNames = [];