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 kMinimum2YearCcExpLength = strlen("12/14"); |
| 367 int current_field_max_length = scanner->Cursor()->max_length; |
| 368 if (current_field_max_length > 0 && |
| 369 current_field_max_length < kMinimum2YearCcExpLength) { |
| 370 return false; |
| 371 } |
| 372 |
365 if (ParseFieldSpecifics(scanner, | 373 if (ParseFieldSpecifics(scanner, |
366 base::UTF8ToUTF16(kExpirationDate2DigitYearRe), | 374 base::UTF8ToUTF16(kExpirationDate2DigitYearRe), |
367 kMatchTelAndSelect, | 375 kMatchTelAndSelect, |
368 &expiration_date_)) { | 376 &expiration_date_)) { |
369 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 377 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
370 expiration_month_ = nullptr; | 378 expiration_month_ = nullptr; |
371 return true; | 379 return true; |
372 } | 380 } |
373 | 381 |
374 if (ParseFieldSpecifics(scanner, | 382 if (ParseFieldSpecifics(scanner, |
375 base::UTF8ToUTF16(kExpirationDateRe), | 383 base::UTF8ToUTF16(kExpirationDateRe), |
376 kMatchTelAndSelect, | 384 kMatchTelAndSelect, |
377 &expiration_date_)) { | 385 &expiration_date_)) { |
| 386 static int kMinimum4YearCcExpLength = strlen("12/2014"); |
| 387 if (current_field_max_length > 0 && |
| 388 current_field_max_length < kMinimum4YearCcExpLength) { |
| 389 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
| 390 } |
378 expiration_month_ = nullptr; | 391 expiration_month_ = nullptr; |
379 return true; | 392 return true; |
380 } | 393 } |
381 | 394 |
382 return false; | 395 return false; |
383 } | 396 } |
384 | 397 |
385 ServerFieldType CreditCardField::GetExpirationYearType() const { | 398 ServerFieldType CreditCardField::GetExpirationYearType() const { |
386 return (expiration_date_ | 399 return (expiration_date_ |
387 ? exp_year_type_ | 400 ? exp_year_type_ |
388 : ((expiration_year_ && expiration_year_->max_length == 2) | 401 : ((expiration_year_ && expiration_year_->max_length == 2) |
389 ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 402 ? CREDIT_CARD_EXP_2_DIGIT_YEAR |
390 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 403 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
391 } | 404 } |
392 | 405 |
393 } // namespace autofill | 406 } // namespace autofill |
OLD | NEW |