Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: components/autofill/core/browser/autofill_manager.cc

Issue 1627843002: [Autofill] Sanitize the credit card field value before matching against user data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stop chars Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_manager.cc
diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc
index 5440ed0932612081576da6fc2055bf85216b8850..83eb14ada33d6723b32949f0c611aae2c8fdaab0 100644
--- a/components/autofill/core/browser/autofill_manager.cc
+++ b/components/autofill/core/browser/autofill_manager.cc
@@ -97,6 +97,18 @@ bool SectionIsAutofilled(const FormStructure& form_structure,
return false;
}
+// Returns the credit card field |value| trimmed from whitespace and with stop
+// characters removed.
+base::string16 SanitizeCreditCardFieldValue(const base::string16& value) {
+ base::string16 sanitized;
+ base::TrimWhitespace(value, base::TRIM_ALL, &sanitized);
+ // Some sites have ____-____-____-____ in their credit card number fields, for
+ // example.
+ base::ReplaceChars(sanitized, base::ASCIIToUTF16("-_"),
+ base::ASCIIToUTF16(""), &sanitized);
+ return sanitized;
+}
+
} // namespace
AutofillManager::AutofillManager(
@@ -1523,8 +1535,11 @@ std::vector<Suggestion> AutofillManager::GetProfileSuggestions(
std::vector<Suggestion> AutofillManager::GetCreditCardSuggestions(
const FormFieldData& field,
const AutofillType& type) const {
+ // The field value is sanitized before attempting to match it to the user's
+ // data.
std::vector<Suggestion> suggestions =
- personal_data_->GetCreditCardSuggestions(type, field.value);
+ personal_data_->GetCreditCardSuggestions(
+ type, SanitizeCreditCardFieldValue(field.value));
for (size_t i = 0; i < suggestions.size(); i++) {
suggestions[i].frontend_id =
MakeFrontendID(suggestions[i].backend_id, std::string());
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698