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

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

Issue 2892813003: Add MATCH_NUMBER to match types when parsing expiration date form field. (Closed)
Patch Set: adds unit-test. Created 3 years, 7 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/credit_card_field_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/credit_card_field.cc
diff --git a/components/autofill/core/browser/credit_card_field.cc b/components/autofill/core/browser/credit_card_field.cc
index 468e1f60e136b6c9a054c7b8599611610f89283b..ea382f76124863ccfbbfaa4130c161238986e348 100644
--- a/components/autofill/core/browser/credit_card_field.cc
+++ b/components/autofill/core/browser/credit_card_field.cc
@@ -425,28 +425,21 @@ bool CreditCardField::ParseExpirationDate(AutofillScanner* scanner) {
// If that fails, do a general regex search.
scanner->RewindTo(month_year_saved_cursor);
- const int kMatchTelAndSelect = MATCH_DEFAULT | MATCH_TELEPHONE | MATCH_SELECT;
- if (ParseFieldSpecifics(scanner,
- base::UTF8ToUTF16(kExpirationMonthRe),
- kMatchTelAndSelect,
- &expiration_month_) &&
- ParseFieldSpecifics(scanner,
- base::UTF8ToUTF16(kExpirationYearRe),
- kMatchTelAndSelect,
- &expiration_year_)) {
+ const int kMatchNumAndTelAndSelect =
+ MATCH_DEFAULT | MATCH_NUMBER | MATCH_TELEPHONE | MATCH_SELECT;
+ if (ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kExpirationMonthRe),
+ kMatchNumAndTelAndSelect, &expiration_month_) &&
+ ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kExpirationYearRe),
+ kMatchNumAndTelAndSelect, &expiration_year_)) {
return true;
}
// If that fails, look for just MM and/or YY(YY).
scanner->RewindTo(month_year_saved_cursor);
- if (ParseFieldSpecifics(scanner,
- base::ASCIIToUTF16("^mm$"),
- kMatchTelAndSelect,
- &expiration_month_) &&
- ParseFieldSpecifics(scanner,
- base::ASCIIToUTF16("^(yy|yyyy)$"),
- kMatchTelAndSelect,
- &expiration_year_)) {
+ if (ParseFieldSpecifics(scanner, base::ASCIIToUTF16("^mm$"),
+ kMatchNumAndTelAndSelect, &expiration_month_) &&
+ ParseFieldSpecifics(scanner, base::ASCIIToUTF16("^(yy|yyyy)$"),
+ kMatchNumAndTelAndSelect, &expiration_year_)) {
return true;
}
@@ -457,25 +450,21 @@ bool CreditCardField::ParseExpirationDate(AutofillScanner* scanner) {
// Bail out if the field cannot fit a 2-digit year expiration date.
const int current_field_max_length = scanner->Cursor()->max_length;
if (!FieldCanFitDataForFieldType(current_field_max_length,
- CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)) {
+ CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))
return false;
- }
// Try to look for a 2-digit year expiration date.
if (ParseFieldSpecifics(scanner,
base::UTF8ToUTF16(kExpirationDate2DigitYearRe),
- kMatchTelAndSelect,
- &expiration_date_)) {
+ kMatchNumAndTelAndSelect, &expiration_date_)) {
exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR;
expiration_month_ = nullptr;
return true;
}
// Try to look for a generic expiration date field. (2 or 4 digit year)
- if (ParseFieldSpecifics(scanner,
- base::UTF8ToUTF16(kExpirationDateRe),
- kMatchTelAndSelect,
- &expiration_date_)) {
+ if (ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kExpirationDateRe),
+ kMatchNumAndTelAndSelect, &expiration_date_)) {
// If such a field exists, but it cannot fit a 4-digit year expiration
// date, then the likely possibility is that it is a 2-digit year expiration
// date.
@@ -492,8 +481,7 @@ bool CreditCardField::ParseExpirationDate(AutofillScanner* scanner) {
CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR) &&
ParseFieldSpecifics(scanner,
base::UTF8ToUTF16(kExpirationDate4DigitYearRe),
- kMatchTelAndSelect,
- &expiration_date_)) {
+ kMatchNumAndTelAndSelect, &expiration_date_)) {
expiration_month_ = nullptr;
return true;
}
« no previous file with comments | « no previous file | components/autofill/core/browser/credit_card_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698