tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 01a985b85b499c01a026671a57d2cadc3aad8354
parent 29419ad5e3ffc8db0d02836645a057b8aa910437
Author: fmasalha <fmasalha@mozilla.com>
Date:   Wed, 10 Dec 2025 13:58:32 +0000

Bug 1905371 - Fixed edge-case field promotion heuristic r=credential-management-reviewers,dimi,NeilDeakin

Previously, the heuristic promoted `address-line2` to `address-line1` whenever `address-line1` was missing. However, this caused incorrect promotions in cases where `address-line1` existed but was skipped from autofill (e.g., due to
`isLookup = true`).

This patch updates the logic so that `address-line2` is only promoted when `address-line1` does not exist at all, not when it merely wasn't filled.

This prevents incorrect overwriting of valid field data while maintaining
correct behavior for forms that genuinely lack an `address-line1` field.

Differential Revision: https://phabricator.services.mozilla.com/D271677

Diffstat:
Mbrowser/extensions/formautofill/test/browser/address/browser_address_street_lookup.js | 36++++++++++++++++++++++++++++++++++++
Mtoolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs | 12+++++++++++-
2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/browser/extensions/formautofill/test/browser/address/browser_address_street_lookup.js b/browser/extensions/formautofill/test/browser/address/browser_address_street_lookup.js @@ -143,4 +143,40 @@ add_autofill_heuristic_tests([ }, ], }, + { + description: + "Address search field (address-line1 lookup) is skipped and address-line2 is not promoted", + fixtureData: ` + <html> + <body> + <form> + <label>First Name: <input id="firstname"></label> + <label>Last Name: <input id="lastname"></label> + <label>Address Lookup: <input id="Address1" placeholder="Enter address or postal code"></label> + <label>Apartment: <input id="apt"></label> + </form> + </body> + </html> + `, + profile: TEST_ADDRESS_1, + expectedResult: [ + { + default: { + reason: "regex-heuristic", + }, + fields: [ + { fieldName: "given-name", autofill: TEST_ADDRESS_1["given-name"] }, + { fieldName: "family-name", autofill: TEST_ADDRESS_1["family-name"] }, + { + fieldName: "address-line1", + autofill: "", + }, + { + fieldName: "address-line2", + autofill: TEST_ADDRESS_1["street-address"].split("\n")[1], + }, + ], + }, + ], + }, ]); diff --git a/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs @@ -429,6 +429,7 @@ export const FormAutofillHeuristics = { // during the update. const fields = []; const fieldIndicies = []; + for (let idx = scanner.parsingIndex; !scanner.parsingFinished; idx++) { const detail = scanner.getFieldDetailByIndex(idx); @@ -450,6 +451,7 @@ export const FormAutofillHeuristics = { if (detail?.isLookup) { lookupFieldsCount++; + continue; // Skip address lookup fields } @@ -497,7 +499,15 @@ export const FormAutofillHeuristics = { } } - if (canUpdate) { + // If the address-line1 field was not found, we promote `address-line2` + // to `address-line1`. If the address-line1 field is a lookup field, we don't + // want to promote another field since it does exist but is not fillable. + if ( + canUpdate && + !scanner.getFieldsMatching( + field => field.fieldName == "address-line1" && field.isLookup + ).length + ) { scanner.updateFieldName(fieldIndicies[0], "address-line1"); } }