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

Side by Side 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 unified diff | Download patch
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/validation.h" 5 #include "components/autofill/core/browser/validation.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 sum += digit / 10 + digit % 10; 80 sum += digit / 10 + digit % 10;
81 } else { 81 } else {
82 sum += digit; 82 sum += digit;
83 } 83 }
84 odd = !odd; 84 odd = !odd;
85 } 85 }
86 86
87 return (sum % 10) == 0; 87 return (sum % 10) == 0;
88 } 88 }
89 89
90 bool IsValidCreditCardSecurityCode(const base::string16& text) { 90 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
91 if (text.size() < 3U || text.size() > 4U) 91 if (text.size() < 3U || text.size() > 4U)
92 return false; 92 return false;
93 93 return base::ContainsOnlyChars(text, base::ASCIIToUTF16("0123456789"));;
Mathieu 2017/01/04 18:20:17 nit: double ;
Moe 2017/01/04 18:31:28 Done.
94 for (const base::char16& it : text) {
95 if (!base::IsAsciiDigit(it))
96 return false;
97 }
98 return true;
99 } 94 }
100 95
101 bool IsValidCreditCardSecurityCode(const base::string16& code, 96 bool IsValidCreditCardSecurityCode(const base::string16& code,
102 const base::string16& number) { 97 const base::string16& number) {
103 const char* const type = CreditCard::GetCreditCardType(number); 98 const char* const card_type = CreditCard::GetCreditCardType(number);
104 size_t required_length = 3; 99 return IsValidCreditCardSecurityCode(code, card_type);
105 if (type == kAmericanExpressCard) 100 }
106 required_length = 4;
107 101
108 return code.length() == required_length; 102 bool IsValidCreditCardSecurityCode(const base::string16& code,
103 const base::StringPiece card_type) {
104 size_t required_length = card_type == kAmericanExpressCard ? 4 : 3;
105 return code.length() == required_length &&
106 base::ContainsOnlyChars(code, base::ASCIIToUTF16("0123456789"));
109 } 107 }
110 108
111 bool IsValidEmailAddress(const base::string16& text) { 109 bool IsValidEmailAddress(const base::string16& text) {
112 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) 110 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state)
113 const base::string16 kEmailPattern = base::ASCIIToUTF16( 111 const base::string16 kEmailPattern = base::ASCIIToUTF16(
114 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" 112 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@"
115 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); 113 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$");
116 return MatchesPattern(text, kEmailPattern); 114 return MatchesPattern(text, kEmailPattern);
117 } 115 }
118 116
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 number_string.begin() + 9), 180 number_string.begin() + 9),
183 &serial) 181 &serial)
184 || serial == 0) { 182 || serial == 0) {
185 return false; 183 return false;
186 } 184 }
187 185
188 return true; 186 return true;
189 } 187 }
190 188
191 } // namespace autofill 189 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698