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 |
382 | |
Evan Stade
2015/04/02 00:42:52
remove \n
| |
374 if (ParseFieldSpecifics(scanner, | 383 if (ParseFieldSpecifics(scanner, |
375 base::UTF8ToUTF16(kExpirationDateRe), | 384 base::UTF8ToUTF16(kExpirationDateRe), |
376 kMatchTelAndSelect, | 385 kMatchTelAndSelect, |
377 &expiration_date_)) { | 386 &expiration_date_)) { |
387 static int kMinimum4YearCcExpLength = strlen("12/2014"); | |
388 if (current_field_max_length > 0 && | |
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 |