Bug 1358960 - "united state" string should not be recognized as "address-level1". r=MattN

MozReview-Commit-ID: E7pmBkGRBkQ

--HG--
extra : rebase_source : 228ad8678b0b01cb99a12b6ded5edd5d82dc0318
This commit is contained in:
Sean Lee 2017-08-04 16:23:45 +08:00
Родитель f0e3ab05cb
Коммит 3fa1506f53
3 изменённых файлов: 46 добавлений и 2 удалений

Просмотреть файл

@ -355,6 +355,16 @@ this.FormAutofillHeuristics = {
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,

Просмотреть файл

@ -121,8 +121,8 @@ var HeuristicsRegExp = {
"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

Просмотреть файл

@ -191,6 +191,40 @@ const TESTCASES = [
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 => {