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

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

Issue 2611863002: Refactors cvc and expiration date validation in CC upload logic as well as unmask prompt. (Closed)
Patch Set: Addressed comment Created 3 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
Index: components/autofill/core/browser/validation.cc
diff --git a/components/autofill/core/browser/validation.cc b/components/autofill/core/browser/validation.cc
index b784a2697937f8e9586e1292376ca73cf164481a..6d2527df3417dc044fdaecf183f7fd8e77eae3f8 100644
--- a/components/autofill/core/browser/validation.cc
+++ b/components/autofill/core/browser/validation.cc
@@ -90,22 +90,20 @@ bool IsValidCreditCardNumber(const base::string16& text) {
bool IsValidCreditCardSecurityCode(const base::string16& text) {
Mathieu 2017/01/04 18:20:17 From quick codesearch, looks like this is unused.
Moe 2017/01/04 18:31:28 Looks like it's being used in https://cs.chromium.
Mathieu 2017/01/04 19:12:37 Yes but I would say the test doesn't count. Let's
Moe 2017/01/05 05:25:20 Oh i see. My bad. Removed the unused functions and
if (text.size() < 3U || text.size() > 4U)
return false;
-
- for (const base::char16& it : text) {
- if (!base::IsAsciiDigit(it))
- return false;
- }
- return true;
+ return base::ContainsOnlyChars(text, base::ASCIIToUTF16("0123456789"));;
Mathieu 2017/01/04 18:20:17 nit: double ;
Moe 2017/01/04 18:31:28 Done.
}
bool IsValidCreditCardSecurityCode(const base::string16& code,
const base::string16& number) {
- const char* const type = CreditCard::GetCreditCardType(number);
- size_t required_length = 3;
- if (type == kAmericanExpressCard)
- required_length = 4;
+ const char* const card_type = CreditCard::GetCreditCardType(number);
+ return IsValidCreditCardSecurityCode(code, card_type);
+}
- return code.length() == required_length;
+bool IsValidCreditCardSecurityCode(const base::string16& code,
+ const base::StringPiece card_type) {
+ size_t required_length = card_type == kAmericanExpressCard ? 4 : 3;
+ return code.length() == required_length &&
+ base::ContainsOnlyChars(code, base::ASCIIToUTF16("0123456789"));
}
bool IsValidEmailAddress(const base::string16& text) {

Powered by Google App Engine
This is Rietveld 408576698