| 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 <memory> | 9 #include <memory> | 
| 10 #include <utility> | 10 #include <utility> | 
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 418       expiration_year_ = scanner->Cursor(); | 418       expiration_year_ = scanner->Cursor(); | 
| 419       scanner->Advance(); | 419       scanner->Advance(); | 
| 420       return true; | 420       return true; | 
| 421     } | 421     } | 
| 422     expiration_month_ = nullptr; | 422     expiration_month_ = nullptr; | 
| 423     expiration_year_ = nullptr; | 423     expiration_year_ = nullptr; | 
| 424   } | 424   } | 
| 425 | 425 | 
| 426   // If that fails, do a general regex search. | 426   // If that fails, do a general regex search. | 
| 427   scanner->RewindTo(month_year_saved_cursor); | 427   scanner->RewindTo(month_year_saved_cursor); | 
| 428   const int kMatchTelAndSelect = MATCH_DEFAULT | MATCH_TELEPHONE | MATCH_SELECT; | 428   const int kMatchNumAndTelAndSelect = | 
| 429   if (ParseFieldSpecifics(scanner, | 429       MATCH_DEFAULT | MATCH_NUMBER | MATCH_TELEPHONE | MATCH_SELECT; | 
| 430                           base::UTF8ToUTF16(kExpirationMonthRe), | 430   if (ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kExpirationMonthRe), | 
| 431                           kMatchTelAndSelect, | 431                           kMatchNumAndTelAndSelect, &expiration_month_) && | 
| 432                           &expiration_month_) && | 432       ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kExpirationYearRe), | 
| 433       ParseFieldSpecifics(scanner, | 433                           kMatchNumAndTelAndSelect, &expiration_year_)) { | 
| 434                           base::UTF8ToUTF16(kExpirationYearRe), |  | 
| 435                           kMatchTelAndSelect, |  | 
| 436                           &expiration_year_)) { |  | 
| 437     return true; | 434     return true; | 
| 438   } | 435   } | 
| 439 | 436 | 
| 440   // If that fails, look for just MM and/or YY(YY). | 437   // If that fails, look for just MM and/or YY(YY). | 
| 441   scanner->RewindTo(month_year_saved_cursor); | 438   scanner->RewindTo(month_year_saved_cursor); | 
| 442   if (ParseFieldSpecifics(scanner, | 439   if (ParseFieldSpecifics(scanner, base::ASCIIToUTF16("^mm$"), | 
| 443                           base::ASCIIToUTF16("^mm$"), | 440                           kMatchNumAndTelAndSelect, &expiration_month_) && | 
| 444                           kMatchTelAndSelect, | 441       ParseFieldSpecifics(scanner, base::ASCIIToUTF16("^(yy|yyyy)$"), | 
| 445                           &expiration_month_) && | 442                           kMatchNumAndTelAndSelect, &expiration_year_)) { | 
| 446       ParseFieldSpecifics(scanner, |  | 
| 447                           base::ASCIIToUTF16("^(yy|yyyy)$"), |  | 
| 448                           kMatchTelAndSelect, |  | 
| 449                           &expiration_year_)) { |  | 
| 450     return true; | 443     return true; | 
| 451   } | 444   } | 
| 452 | 445 | 
| 453   // If that fails, try to parse a combined expiration field. | 446   // If that fails, try to parse a combined expiration field. | 
| 454   // We allow <select> fields, because they're used e.g. on qvc.com. | 447   // We allow <select> fields, because they're used e.g. on qvc.com. | 
| 455   scanner->RewindTo(month_year_saved_cursor); | 448   scanner->RewindTo(month_year_saved_cursor); | 
| 456 | 449 | 
| 457   // Bail out if the field cannot fit a 2-digit year expiration date. | 450   // Bail out if the field cannot fit a 2-digit year expiration date. | 
| 458   const int current_field_max_length = scanner->Cursor()->max_length; | 451   const int current_field_max_length = scanner->Cursor()->max_length; | 
| 459   if (!FieldCanFitDataForFieldType(current_field_max_length, | 452   if (!FieldCanFitDataForFieldType(current_field_max_length, | 
| 460                                    CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)) { | 453                                    CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)) | 
| 461     return false; | 454     return false; | 
| 462   } |  | 
| 463 | 455 | 
| 464   // Try to look for a 2-digit year expiration date. | 456   // Try to look for a 2-digit year expiration date. | 
| 465   if (ParseFieldSpecifics(scanner, | 457   if (ParseFieldSpecifics(scanner, | 
| 466                           base::UTF8ToUTF16(kExpirationDate2DigitYearRe), | 458                           base::UTF8ToUTF16(kExpirationDate2DigitYearRe), | 
| 467                           kMatchTelAndSelect, | 459                           kMatchNumAndTelAndSelect, &expiration_date_)) { | 
| 468                           &expiration_date_)) { |  | 
| 469     exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 460     exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 
| 470     expiration_month_ = nullptr; | 461     expiration_month_ = nullptr; | 
| 471     return true; | 462     return true; | 
| 472   } | 463   } | 
| 473 | 464 | 
| 474   // Try to look for a generic expiration date field. (2 or 4 digit year) | 465   // Try to look for a generic expiration date field. (2 or 4 digit year) | 
| 475   if (ParseFieldSpecifics(scanner, | 466   if (ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kExpirationDateRe), | 
| 476                           base::UTF8ToUTF16(kExpirationDateRe), | 467                           kMatchNumAndTelAndSelect, &expiration_date_)) { | 
| 477                           kMatchTelAndSelect, |  | 
| 478                           &expiration_date_)) { |  | 
| 479     // If such a field exists, but it cannot fit a 4-digit year expiration | 468     // If such a field exists, but it cannot fit a 4-digit year expiration | 
| 480     // date, then the likely possibility is that it is a 2-digit year expiration | 469     // date, then the likely possibility is that it is a 2-digit year expiration | 
| 481     // date. | 470     // date. | 
| 482     if (!FieldCanFitDataForFieldType(current_field_max_length, | 471     if (!FieldCanFitDataForFieldType(current_field_max_length, | 
| 483                                      CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR)) { | 472                                      CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR)) { | 
| 484       exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 473       exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 
| 485     } | 474     } | 
| 486     expiration_month_ = nullptr; | 475     expiration_month_ = nullptr; | 
| 487     return true; | 476     return true; | 
| 488   } | 477   } | 
| 489 | 478 | 
| 490   // Try to look for a 4-digit year expiration date. | 479   // Try to look for a 4-digit year expiration date. | 
| 491   if (FieldCanFitDataForFieldType(current_field_max_length, | 480   if (FieldCanFitDataForFieldType(current_field_max_length, | 
| 492                                   CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR) && | 481                                   CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR) && | 
| 493       ParseFieldSpecifics(scanner, | 482       ParseFieldSpecifics(scanner, | 
| 494                           base::UTF8ToUTF16(kExpirationDate4DigitYearRe), | 483                           base::UTF8ToUTF16(kExpirationDate4DigitYearRe), | 
| 495                           kMatchTelAndSelect, | 484                           kMatchNumAndTelAndSelect, &expiration_date_)) { | 
| 496                           &expiration_date_)) { |  | 
| 497     expiration_month_ = nullptr; | 485     expiration_month_ = nullptr; | 
| 498     return true; | 486     return true; | 
| 499   } | 487   } | 
| 500 | 488 | 
| 501   return false; | 489   return false; | 
| 502 } | 490 } | 
| 503 | 491 | 
| 504 ServerFieldType CreditCardField::GetExpirationYearType() const { | 492 ServerFieldType CreditCardField::GetExpirationYearType() const { | 
| 505   return (expiration_date_ | 493   return (expiration_date_ | 
| 506               ? exp_year_type_ | 494               ? exp_year_type_ | 
| 507               : ((expiration_year_ && expiration_year_->max_length == 2) | 495               : ((expiration_year_ && expiration_year_->max_length == 2) | 
| 508                      ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 496                      ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 
| 509                      : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 497                      : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 
| 510 } | 498 } | 
| 511 | 499 | 
| 512 bool CreditCardField::HasExpiration() const { | 500 bool CreditCardField::HasExpiration() const { | 
| 513   return expiration_date_ || (expiration_month_ && expiration_year_); | 501   return expiration_date_ || (expiration_month_ && expiration_year_); | 
| 514 } | 502 } | 
| 515 | 503 | 
| 516 }  // namespace autofill | 504 }  // namespace autofill | 
| OLD | NEW | 
|---|