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

Side by Side 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, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 for (size_t i = 0; i < form_structure.field_count(); ++i) { 90 for (size_t i = 0; i < form_structure.field_count(); ++i) {
91 if (form_structure.field(i)->section() == section && 91 if (form_structure.field(i)->section() == section &&
92 form.fields[i].is_autofilled) { 92 form.fields[i].is_autofilled) {
93 return true; 93 return true;
94 } 94 }
95 } 95 }
96 96
97 return false; 97 return false;
98 } 98 }
99 99
100 // Returns the credit card field |value| trimmed from whitespace and with stop
101 // characters removed.
102 base::string16 SanitizeCreditCardFieldValue(const base::string16& value) {
103 base::string16 sanitized;
104 base::TrimWhitespace(value, base::TRIM_ALL, &sanitized);
105 // Some sites have ____-____-____-____ in their credit card number fields, for
106 // example.
107 base::ReplaceChars(sanitized, base::ASCIIToUTF16("-_"),
108 base::ASCIIToUTF16(""), &sanitized);
109 return sanitized;
110 }
111
100 } // namespace 112 } // namespace
101 113
102 AutofillManager::AutofillManager( 114 AutofillManager::AutofillManager(
103 AutofillDriver* driver, 115 AutofillDriver* driver,
104 AutofillClient* client, 116 AutofillClient* client,
105 const std::string& app_locale, 117 const std::string& app_locale,
106 AutofillDownloadManagerState enable_download_manager) 118 AutofillDownloadManagerState enable_download_manager)
107 : driver_(driver), 119 : driver_(driver),
108 client_(client), 120 client_(client),
109 payments_client_( 121 payments_client_(
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 for (size_t i = 0; i < suggestions.size(); ++i) { 1528 for (size_t i = 0; i < suggestions.size(); ++i) {
1517 suggestions[i].frontend_id = 1529 suggestions[i].frontend_id =
1518 MakeFrontendID(std::string(), suggestions[i].backend_id); 1530 MakeFrontendID(std::string(), suggestions[i].backend_id);
1519 } 1531 }
1520 return suggestions; 1532 return suggestions;
1521 } 1533 }
1522 1534
1523 std::vector<Suggestion> AutofillManager::GetCreditCardSuggestions( 1535 std::vector<Suggestion> AutofillManager::GetCreditCardSuggestions(
1524 const FormFieldData& field, 1536 const FormFieldData& field,
1525 const AutofillType& type) const { 1537 const AutofillType& type) const {
1538 // The field value is sanitized before attempting to match it to the user's
1539 // data.
1526 std::vector<Suggestion> suggestions = 1540 std::vector<Suggestion> suggestions =
1527 personal_data_->GetCreditCardSuggestions(type, field.value); 1541 personal_data_->GetCreditCardSuggestions(
1542 type, SanitizeCreditCardFieldValue(field.value));
1528 for (size_t i = 0; i < suggestions.size(); i++) { 1543 for (size_t i = 0; i < suggestions.size(); i++) {
1529 suggestions[i].frontend_id = 1544 suggestions[i].frontend_id =
1530 MakeFrontendID(suggestions[i].backend_id, std::string()); 1545 MakeFrontendID(suggestions[i].backend_id, std::string());
1531 } 1546 }
1532 return suggestions; 1547 return suggestions;
1533 } 1548 }
1534 1549
1535 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { 1550 void AutofillManager::ParseForms(const std::vector<FormData>& forms) {
1536 if (forms.empty()) 1551 if (forms.empty())
1537 return; 1552 return;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 if (i > 0) 1722 if (i > 0)
1708 fputs("Next oldest form:\n", file); 1723 fputs("Next oldest form:\n", file);
1709 } 1724 }
1710 fputs("\n", file); 1725 fputs("\n", file);
1711 1726
1712 fclose(file); 1727 fclose(file);
1713 } 1728 }
1714 #endif // ENABLE_FORM_DEBUG_DUMP 1729 #endif // ENABLE_FORM_DEBUG_DUMP
1715 1730
1716 } // namespace autofill 1731 } // namespace autofill
OLDNEW
« 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