commit 0d35cf32e8542433880cb5b4e33a1dbf89d11df7
parent 732d3a16fec5707f37ac8df7a35e2a928351ca9a
Author: Neil Deakin <neil@mozilla.com>
Date: Tue, 16 Dec 2025 14:47:40 +0000
Bug 1999525, match as tel-national when a tel field appears after a tel-country-code field, r=dimi,credential-management-reviewers
The check for options in country dropdowns is moved later otherwise we miss matching the tel-country-code when needed.
Differential Revision: https://phabricator.services.mozilla.com/D275141
Diffstat:
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs
@@ -347,15 +347,25 @@ export const FormAutofillHeuristics = {
}
}
- // If the previous parsed field is a "tel" field, run heuristic to see
- // if the current field is a "tel-extension" field
const field = scanner.getFieldDetailByIndex(scanner.parsingIndex);
- if (field && field.reason != "autocomplete") {
+ if (field) {
const prev = scanner.getFieldDetailByIndex(scanner.parsingIndex - 1);
+
+ // If there is a country code, then the next field should be
+ // 'tel-national' not 'tel'.
if (
+ prev?.fieldName == "tel-country-code" &&
+ field.fieldName == "tel" &&
+ field.reason != "autocomplete"
+ ) {
+ scanner.updateFieldName(scanner.parsingIndex, "tel-national");
+ scanner.parsingIndex++;
+ } else if (
prev &&
lazy.FormAutofillUtils.getCategoryFromFieldName(prev.fieldName) == "tel"
) {
+ // If the previous parsed field is a "tel" field, run heuristic to see
+ // if the current field is a "tel-extension" field
const regExpTelExtension = new RegExp(
"\\bext|ext\\b|extension|ramal", // pt-BR, pt-PT
"iug"
@@ -1113,7 +1123,12 @@ export const FormAutofillHeuristics = {
countryDisplayNames.includes(option.text)
)
) {
- return ["country", inferredInfo];
+ // Now that it is likely a country dropdown field, check if it is
+ // a telephone country prefix or a separate country field.
+ return this._findMatchedFieldNames(element, ["tel-country-code"])
+ ?.length
+ ? ["tel-country-code", inferredInfo]
+ : ["country", inferredInfo];
}
}