Index: components/autofill/core/browser/autofill_field.cc |
diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc |
index 75a0d0a4220a61e4f8f9c92a523bbb12363974cf..283636de09f5a01baa64e387bcb7c3a34917c4b0 100644 |
--- a/components/autofill/core/browser/autofill_field.cc |
+++ b/components/autofill/core/browser/autofill_field.cc |
@@ -13,6 +13,7 @@ |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "components/autofill/core/browser/autofill_country.h" |
+#include "components/autofill/core/browser/autofill_regexes.h" |
#include "components/autofill/core/browser/autofill_type.h" |
#include "components/autofill/core/browser/phone_number.h" |
#include "components/autofill/core/browser/state_names.h" |
@@ -248,26 +249,10 @@ bool FillYearSelectControl(const base::string16& value, |
// given |field|. |
bool FillCreditCardTypeSelectControl(const base::string16& value, |
FormFieldData* field) { |
- // Try stripping off spaces. |
- base::string16 value_stripped; |
- base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16, |
- &value_stripped); |
- |
- for (size_t i = 0; i < field->option_values.size(); ++i) { |
- base::string16 option_value_lowercase; |
- base::RemoveChars(base::StringToLowerASCII(field->option_values[i]), |
- base::kWhitespaceUTF16, &option_value_lowercase); |
- base::string16 option_contents_lowercase; |
- base::RemoveChars(base::StringToLowerASCII(field->option_contents[i]), |
- base::kWhitespaceUTF16, &option_contents_lowercase); |
- |
- // Perform a case-insensitive comparison; but fill the form with the |
- // original text, not the lowercased version. |
- if (value_stripped == option_value_lowercase || |
- value_stripped == option_contents_lowercase) { |
- field->value = field->option_values[i]; |
- return true; |
- } |
+ size_t idx; |
+ if (AutofillField::FindValueInCreditTypeSelectControl(*field, value, &idx)) { |
+ field->value = field->option_values[idx]; |
+ return true; |
} |
// For American Express, also try filling as "AmEx". |
@@ -541,4 +526,20 @@ base::string16 AutofillField::GetPhoneNumberValue( |
return number; |
} |
+// static |
+bool AutofillField::FindValueInCreditTypeSelectControl( |
+ const FormFieldData& field, |
+ const base::string16& regex, |
+ size_t* index) { |
+ for (size_t i = 0; i < field.option_values.size(); ++i) { |
+ if (MatchesPattern(field.option_values[i], regex) || |
+ MatchesPattern(field.option_contents[i], regex)) { |
+ if (index) |
+ *index = i; |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
} // namespace autofill |