Commit 7c603c79 authored by Elizabeth Popova's avatar Elizabeth Popova Committed by Chromium LUCI CQ

[Autofill] Prevent parsing of address name as honorific prefix

Prior to this change, an address label field with name "title" was
misclassified as an honorific prefix, because the exclude check was
performed after the honorific prefix has been parsed. Now address name
fields are excluded prior to the honorific parsing.

Bug: 1154727
Change-Id: If5b395b0560f556dfbafd619e336305577582dfb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602126Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Elizabeth Popova <lizapopova@google.com>
Cr-Commit-Position: refs/heads/master@{#840180}
parent e8394460
......@@ -210,6 +210,14 @@ FirstTwoLastNamesField::ParseComponentNames(AutofillScanner* scanner,
// Allow name fields to appear in any order.
while (!scanner->IsEnd()) {
// Skip over address label fields, which can have misleading names
// e.g. "title" or "name".
if (ParseFieldSpecifics(scanner, UTF8ToUTF16(kAddressNameIgnoredRe),
MATCH_DEFAULT, address_name_ignored_patterns,
nullptr, {log_manager, "kAddressNameIgnoredRe"})) {
continue;
}
// Scan for the honorific prefix before checking for unrelated name fields
// because a honorific prefix field is expected to have very specific labels
// including "Title:". The latter is matched with |kNameIgnoredRe|.
......@@ -226,10 +234,7 @@ FirstTwoLastNamesField::ParseComponentNames(AutofillScanner* scanner,
if (ParseFieldSpecifics(scanner, UTF8ToUTF16(kNameIgnoredRe),
MATCH_DEFAULT | MATCH_SELECT | MATCH_SEARCH,
name_ignored_patterns, nullptr,
{log_manager, "kNameIgnoredRe"}) ||
ParseFieldSpecifics(scanner, UTF8ToUTF16(kAddressNameIgnoredRe),
MATCH_DEFAULT, address_name_ignored_patterns,
nullptr, {log_manager, "kAddressNameIgnoredRe"})) {
{log_manager, "kNameIgnoredRe"})) {
continue;
}
......@@ -362,6 +367,14 @@ std::unique_ptr<FirstLastNameField> FirstLastNameField::ParseComponentNames(
page_language);
while (!scanner->IsEnd()) {
// Skip over address label fields, which can have misleading names
// e.g. "title" or "name".
if (ParseFieldSpecifics(scanner, UTF8ToUTF16(kAddressNameIgnoredRe),
MATCH_DEFAULT, address_name_ignored_patterns,
nullptr, {log_manager, "kAddressNameIgnoredRe"})) {
continue;
}
// Scan for the honorific prefix before checking for unrelated fields
// because a honorific prefix field is expected to have very specific labels
// including "Title:". The latter is matched with |kNameIgnoredRe|.
......@@ -381,10 +394,7 @@ std::unique_ptr<FirstLastNameField> FirstLastNameField::ParseComponentNames(
if (ParseFieldSpecifics(scanner, UTF8ToUTF16(kNameIgnoredRe),
MATCH_DEFAULT | MATCH_SELECT | MATCH_SEARCH,
name_ignored_patterns, nullptr,
{log_manager, "kNameIgnoredRe"}) ||
ParseFieldSpecifics(scanner, UTF8ToUTF16(kAddressNameIgnoredRe),
MATCH_DEFAULT, address_name_ignored_patterns,
nullptr, {log_manager, "kAddressNameIgnoredRe"})) {
{log_manager, "kNameIgnoredRe"})) {
continue;
}
......
......@@ -547,7 +547,7 @@ TEST_F(NameFieldTest, HispanicLastNameRegexConverage) {
}
}
// Tests that address name is not misclassified as name.
// Tests that address name is not misclassified as name or honorific prefix.
TEST_F(NameFieldTest, NotAddressName) {
FormFieldData field;
field.form_control_type = "text";
......@@ -557,6 +557,11 @@ TEST_F(NameFieldTest, NotAddressName) {
field.unique_renderer_id = MakeFieldRendererId();
list_.push_back(std::make_unique<AutofillField>(field));
field.label = base::UTF8ToUTF16("Adres Adı");
field.name = base::UTF8ToUTF16("title");
field.unique_renderer_id = MakeFieldRendererId();
list_.push_back(std::make_unique<AutofillField>(field));
AutofillScanner scanner(list_);
field_ = Parse(&scanner);
ASSERT_EQ(nullptr, field_.get());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment