Commit 7b08008c authored by Mariia Shvedchenko's avatar Mariia Shvedchenko Committed by Commit Bot

[Autofill] Add changes to fix tests.

The MatchingPattern's negative pattern type from std::string to base::Optional<std::string> has been changed and the resulting changes have been made. This fixes that every pattern's negative pattern vacuously matched.

Bug: 1142579
Change-Id: Ida580b33e9a4f0f42accdfcce082aa428ad12275
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500221Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Commit-Queue: Christoph Schwering <schwering@google.com>
Commit-Queue: Mariia Shvedchenko <mariiash@google.com>
Cr-Commit-Position: refs/heads/master@{#821023}
parent f9a33ab2
......@@ -5,6 +5,7 @@
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_PARSING_AUTOFILL_PARSING_UTILS_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_PARSING_AUTOFILL_PARSING_UTILS_H_
#include <base/optional.h>
#include <string>
namespace autofill {
......@@ -51,7 +52,7 @@ struct MatchingPattern {
std::string pattern_identifier;
std::string positive_pattern;
float positive_score = 1.1f;
std::string negative_pattern;
base::Optional<std::string> negative_pattern;
int match_field_attributes;
int match_field_input_types;
std::string language;
......
......@@ -207,7 +207,9 @@ bool FormField::ParseFieldSpecifics(
if (base::FeatureList::IsEnabled(
features::
kAutofillApplyNegativePatternsForFieldTypeDetectionHeuristics)) {
if (FormField::Match(field, base::UTF8ToUTF16(pattern.negative_pattern),
if (pattern.negative_pattern.has_value() &&
FormField::Match(field,
base::UTF8ToUTF16(pattern.negative_pattern.value()),
pattern.match_field_attributes,
pattern.match_field_input_types, logging)) {
continue;
......
......@@ -47,15 +47,19 @@ bool ParseMatchingPattern(PatternProvider::Map& patterns,
base::Optional<int> match_field_input_types =
value.FindIntKey(kMatchFieldInputTypesKey);
if (!pattern_identifier || !positive_pattern || !negative_pattern ||
!positive_score || !match_field_attributes || !match_field_input_types)
if (!pattern_identifier || !positive_pattern || !positive_score ||
!match_field_attributes || !match_field_input_types)
return false;
autofill::MatchingPattern new_pattern;
new_pattern.pattern_identifier = *pattern_identifier;
new_pattern.positive_pattern = *positive_pattern;
new_pattern.positive_score = *positive_score;
new_pattern.negative_pattern = *negative_pattern;
if (negative_pattern != nullptr) {
new_pattern.negative_pattern = *negative_pattern;
} else {
new_pattern.negative_pattern = base::nullopt;
}
new_pattern.match_field_attributes = match_field_attributes.value();
new_pattern.match_field_input_types = match_field_input_types.value();
new_pattern.language = language;
......
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