OLD | NEW |
---|---|
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/credit_card_field.h" | 5 #include "components/autofill/core/browser/credit_card_field.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 base::ASCIIToUTF16("^(yy|yyyy)$"), | 355 base::ASCIIToUTF16("^(yy|yyyy)$"), |
356 kMatchTelAndSelect, | 356 kMatchTelAndSelect, |
357 &expiration_year_)) { | 357 &expiration_year_)) { |
358 return true; | 358 return true; |
359 } | 359 } |
360 | 360 |
361 // If that fails, try to parse a combined expiration field. | 361 // If that fails, try to parse a combined expiration field. |
362 // Look for a 2-digit year first. | 362 // Look for a 2-digit year first. |
363 // We allow <select> fields, because they're used e.g. on qvc.com. | 363 // We allow <select> fields, because they're used e.g. on qvc.com. |
364 scanner->RewindTo(month_year_saved_cursor); | 364 scanner->RewindTo(month_year_saved_cursor); |
365 | |
366 static int kMinimum4YearCcExpLength = strlen("2014-12"); | |
Evan Stade
2015/04/01 23:08:27
I guess it's a nit but why is this 2014-12 instead
Lei Zhang
2015/04/02 00:30:13
Done.
| |
367 static int kMinimum2YearCcExpLength = strlen("12/14"); | |
368 int current_field_max_length = scanner->Cursor()->max_length; | |
369 if (current_field_max_length > 0 && | |
370 current_field_max_length < kMinimum2YearCcExpLength) { | |
371 return false; | |
372 } | |
373 | |
365 if (ParseFieldSpecifics(scanner, | 374 if (ParseFieldSpecifics(scanner, |
366 base::UTF8ToUTF16(kExpirationDate2DigitYearRe), | 375 base::UTF8ToUTF16(kExpirationDate2DigitYearRe), |
367 kMatchTelAndSelect, | 376 kMatchTelAndSelect, |
368 &expiration_date_)) { | 377 &expiration_date_)) { |
369 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 378 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
370 expiration_month_ = nullptr; | 379 expiration_month_ = nullptr; |
371 return true; | 380 return true; |
372 } | 381 } |
373 | 382 |
383 | |
374 if (ParseFieldSpecifics(scanner, | 384 if (ParseFieldSpecifics(scanner, |
375 base::UTF8ToUTF16(kExpirationDateRe), | 385 base::UTF8ToUTF16(kExpirationDateRe), |
376 kMatchTelAndSelect, | 386 kMatchTelAndSelect, |
377 &expiration_date_)) { | 387 &expiration_date_)) { |
388 if (current_field_max_length > 0 && | |
Evan Stade
2015/04/01 23:08:26
for consistency with the 2digit year case, shouldn
Lei Zhang
2015/04/02 00:30:13
|kExpirationDateRe| isn't only for 4 digit years.
| |
389 current_field_max_length < kMinimum4YearCcExpLength) { | |
390 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | |
391 } | |
378 expiration_month_ = nullptr; | 392 expiration_month_ = nullptr; |
379 return true; | 393 return true; |
380 } | 394 } |
381 | 395 |
382 return false; | 396 return false; |
383 } | 397 } |
384 | 398 |
385 ServerFieldType CreditCardField::GetExpirationYearType() const { | 399 ServerFieldType CreditCardField::GetExpirationYearType() const { |
386 return (expiration_date_ | 400 return (expiration_date_ |
387 ? exp_year_type_ | 401 ? exp_year_type_ |
388 : ((expiration_year_ && expiration_year_->max_length == 2) | 402 : ((expiration_year_ && expiration_year_->max_length == 2) |
389 ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 403 ? CREDIT_CARD_EXP_2_DIGIT_YEAR |
390 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 404 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
391 } | 405 } |
392 | 406 |
393 } // namespace autofill | 407 } // namespace autofill |
OLD | NEW |