Bug 1390433 - (From 1358960)"united state" string should not be recognized as "address-level1". r=MattN
MozReview-Commit-ID: E7pmBkGRBkQ
--- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm
+++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm
@@ -350,16 +350,26 @@ this.FormAutofillHeuristics = {
labelStrings.push(...FormAutofillUtils.extractLabelStrings(label));
}
}
yield *labelStrings;
};
for (let regexp of regexps) {
for (let string of getElementStrings) {
+ // The original regexp "(?<!united )state|county|region|province" for
+ // "address-line1" wants to exclude any "united state" string, so the
+ // following code is to remove all "united state" string before applying
+ // "addess-level1" regexp.
+ //
+ // Since "united state" string matches to the regexp of address-line2&3,
+ // the two regexps should be excluded here.
+ if (["address-level1", "address-line2", "address-line3"].includes(regexp)) {
+ string = string.toLowerCase().split("united state").join("");
+ }
if (this.RULES[regexp].test(string)) {
return {
fieldName: regexp,
section: "",
addressType: "",
contactType: "",
};
}
--- a/browser/extensions/formautofill/content/heuristicsRegexp.js
+++ b/browser/extensions/formautofill/content/heuristicsRegexp.js
@@ -116,18 +116,18 @@ var HeuristicsRegExp = {
"|cidade" + // pt-BR, pt-PT
"|Город" + // ru
"|市" + // zh-CN
"|分區" + // zh-TW
"|^시[^도·・]|시[·・]?군[·・]?구", // ko-KR
"iu"
),
"address-level1": new RegExp(
- // TODO: [Bug 1358960] JS does not support backward matching, and we
- // should apply this pattern in JS rather than regexp.
+ // JS does not support backward matching, so the following pattern is
+ // applied in FormAutofillHeuristics.getInfo() rather than regexp.
// "(?<!united )state|county|region|province"
"state|county|region|province" +
"|land" + // de-DE
"|county|principality" + // en-UK
"|都道府県" + // ja-JP
"|estado|provincia" + // pt-BR, pt-PT
"|область" + // ru
"|省" + // zh-CN
--- a/browser/extensions/formautofill/test/unit/test_getInfo.js
+++ b/browser/extensions/formautofill/test/unit/test_getInfo.js
@@ -186,16 +186,50 @@ const TESTCASES = [
elementId: "targetElement",
expectedReturnValue: {
fieldName: "email",
section: "",
addressType: "",
contactType: "",
},
},
+ {
+ description: "Exclude United State string",
+ document: `<label>United State
+ <input id="targetElement" />
+ </label>`,
+ elementId: "targetElement",
+ expectedReturnValue: null,
+ },
+ {
+ description: "\"County\" field with \"United State\" string",
+ document: `<label>United State County
+ <input id="targetElement" />
+ </label>`,
+ elementId: "targetElement",
+ expectedReturnValue: {
+ fieldName: "address-level1",
+ section: "",
+ addressType: "",
+ contactType: "",
+ },
+ },
+ {
+ description: "\"city\" field with double \"United State\" string",
+ document: `<label>United State united sTATE city
+ <input id="targetElement" />
+ </label>`,
+ elementId: "targetElement",
+ expectedReturnValue: {
+ fieldName: "address-level2",
+ section: "",
+ addressType: "",
+ contactType: "",
+ },
+ },
];
TESTCASES.forEach(testcase => {
add_task(async function() {
do_print("Starting testcase: " + testcase.description);
let doc = MockDocument.createTestDocument(
"http://localhost:8080/test/", testcase.document);