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

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

Issue 17099006: Validate saved credit card number in interactive autocomplete (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge master Created 7 years, 6 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 ca8c780ecdae02ab13efddf2d26dff3ea380a4cc..139388fc320e090caebfc7270d170867da6eb4ef 100644
--- a/components/autofill/core/browser/validation.cc
+++ b/components/autofill/core/browser/validation.cc
@@ -33,21 +33,27 @@ bool IsValidCreditCardExpirationDate(const base::string16& year,
if (year_cleaned.length() != 4)
return false;
+ int cc_year;
+ if (!base::StringToInt(year_cleaned, &cc_year))
+ return false;
+
+ int cc_month;
+ if (!base::StringToInt(month_cleaned, &cc_month))
+ return false;
+
+ return IsValidCreditCardExpirationDate(cc_year, cc_month, now);
+}
+
+bool IsValidCreditCardExpirationDate(int year,
+ int month,
+ const base::Time& now) {
base::Time::Exploded now_exploded;
now.LocalExplode(&now_exploded);
- size_t current_year = size_t(now_exploded.year);
- size_t current_month = size_t(now_exploded.month);
- size_t cc_year;
- if (!base::StringToSizeT(year_cleaned, &cc_year))
- return false;
- if (cc_year < current_year)
+ if (year < now_exploded.year)
return false;
- size_t cc_month;
- if (!base::StringToSizeT(month_cleaned, &cc_month))
- return false;
- if (cc_year == current_year && cc_month < current_month)
+ if (year == now_exploded.year && month < now_exploded.month)
return false;
return true;
« no previous file with comments | « components/autofill/core/browser/validation.h ('k') | components/autofill/core/browser/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698