Bug 1428292 - Determine tel-extension in telephone parser only. r=lchang
MozReview-Commit-ID: KRArH8kxuu0
--- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm
+++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm
@@ -177,28 +177,25 @@ class FieldScanner {
*/
pushDetail() {
let elementIndex = this.fieldDetails.length;
if (elementIndex >= this._elements.length) {
throw new Error("Try to push the non-existing element info.");
}
let element = this._elements[elementIndex];
let info = FormAutofillHeuristics.getInfo(element);
- if (!info) {
- info = {};
- }
let fieldInfo = {
- section: info.section,
- addressType: info.addressType,
- contactType: info.contactType,
- fieldName: info.fieldName,
+ section: info ? info.section : "",
+ addressType: info ? info.addressType : "",
+ contactType: info ? info.contactType : "",
+ fieldName: info ? info.fieldName : "",
elementWeakRef: Cu.getWeakReference(element),
};
- if (info._reason) {
+ if (info && info._reason) {
fieldInfo._reason = info._reason;
}
this.fieldDetails.push(fieldInfo);
this._pushToSection(this._getSectionName(fieldInfo), fieldInfo);
}
_getSectionName(info) {
@@ -534,19 +531,29 @@ this.FormAutofillHeuristics = {
}
}
if (fieldScanner.parsingFinished) {
return parsedField;
}
let nextField = fieldScanner.getFieldDetailByIndex(fieldScanner.parsingIndex);
- if (nextField && nextField.fieldName == "tel-extension") {
- fieldScanner.parsingIndex++;
- parsedField = true;
+ if (nextField && nextField._reason != "autocomplete" && fieldScanner.parsingIndex > 0) {
+ const regExpTelExtension = new RegExp(
+ "\\bext|ext\\b|extension" +
+ "|ramal", // pt-BR, pt-PT
+ "iu");
+ const previousField = fieldScanner.getFieldDetailByIndex(fieldScanner.parsingIndex - 1);
+ const previousFieldType = FormAutofillUtils.getCategoryFromFieldName(previousField.fieldName);
+ if (previousField && previousFieldType == "tel" &&
+ this._matchRegexp(nextField.elementWeakRef.get(), regExpTelExtension)) {
+ fieldScanner.updateFieldName(fieldScanner.parsingIndex, "tel-extension");
+ fieldScanner.parsingIndex++;
+ parsedField = true;
+ }
}
return parsedField;
},
/**
* Try to find the correct address-line[1-3] sequence and correct their field
* names.
--- a/browser/extensions/formautofill/content/heuristicsRegexp.js
+++ b/browser/extensions/formautofill/content/heuristicsRegexp.js
@@ -24,21 +24,16 @@ var HeuristicsRegExp = {
"|Электронной.?Почты" + // ru
"|邮件|邮箱" + // zh-CN
"|電郵地址" + // zh-TW
"|(?:이메일|전자.?우편|[Ee]-?mail)(.?주소)?", // ko-KR
"iu"
),
// ==== Telephone ====
- "tel-extension": new RegExp(
- "\\bext|ext\\b|extension" +
- "|ramal", // pt-BR, pt-PT
- "iu"
- ),
"tel": new RegExp(
"phone|mobile|contact.?number" +
"|telefonnummer" + // de-DE
"|telefono|teléfono" + // es
"|telfixe" + // fr-FR
"|電話" + // ja-JP
"|telefone|telemovel" + // pt-BR, pt-PT
"|телефон" + // ru
--- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js
+++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js
@@ -10,52 +10,40 @@ runHeuristicsTest([
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "organization"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"}, // city
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
{"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
-
- // FIXME: bug 1392932 - misdetect ZIP ext string
- {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
- ], [
- // The below "tel-extension" is correct and removed due to the
- // duplicated field above.
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
]],
[],
],
}, {
fixturePath: "Checkout_BillingPaymentInfo.html",
expectedResult: [
[[
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "organization"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"}, // city
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
{"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
-
- // FIXME: bug 1392932 - misdetect ZIP ext string
- {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
], [
// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off
{"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"},
-
// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"},
- ], [
- {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
]],
[],
],
}, {
fixturePath: "Checkout_Logon.html",
expectedResult: [
[],
[],
--- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Walmart.js
+++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Walmart.js
@@ -31,22 +31,16 @@ runHeuristicsTest([
{"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "given-name"},
{"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "family-name"},
{"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "tel"},
], [
{"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-number"},
{"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"},
{"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"},
// {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-csc"},
- ], [
- // FIXME bug 1392932 - the following field shouldn't be recognized as
- // "tel-extension".
- // The wrong prediction is caused by the name attr "brwsrAutofillText"
- // which matches the regexp "ext\\b".
- {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
],
],
],
}, {
fixturePath: "Shipping.html",
expectedResult: [
[[
{"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},