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

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

Issue 2025063002: [Autofill] Truncate expiration year based on prediction and max length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/autofill_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/autofill_field.cc
diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc
index e6362deabbbaf19d1b95d9f17da72824345ffe33..19f2ce8ca0fcbdd76865f84558f6b3cb981e017b 100644
--- a/components/autofill/core/browser/autofill_field.cc
+++ b/components/autofill/core/browser/autofill_field.cc
@@ -440,6 +440,28 @@ bool FillStateText(const base::string16& value, FormFieldData* field) {
return false;
}
+// Fills the expiration year |value| into the |field|. Uses the |field_type|
+// and the |field|'s max_length attribute to determine if the |value| needs to
+// be truncated.
+void FillExpirationYearInput(base::string16 value,
+ ServerFieldType field_type,
+ FormFieldData* field) {
+ // If the |field_type| requires only 2 digits, keep only the last 2 digits of
+ // |value|.
+ if (field_type == CREDIT_CARD_EXP_2_DIGIT_YEAR && value.length() > 2)
+ value = value.substr(value.length() - 2, 2);
+
+ if (field->max_length == 0 || field->max_length >= value.size()) {
+ // No length restrictions, fill the year value directly.
+ field->value = value;
+ } else {
+ // Truncate the front of |value| to keep only the number of characters equal
+ // to the |field|'s max length.
+ field->value =
+ value.substr(value.length() - field->max_length, field->max_length);
+ }
+}
+
std::string Hash32Bit(const std::string& str) {
std::string hash_bin = base::SHA1HashString(str);
DCHECK_EQ(base::kSHA1Length, hash_bin.length());
@@ -594,6 +616,11 @@ bool AutofillField::FillFormField(const AutofillField& field,
return true;
} else if (type.GetStorableType() == ADDRESS_HOME_STATE) {
return FillStateText(value, field_data);
+ } else if (field_data->form_control_type == "input" &&
+ (type.GetStorableType() == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
+ type.GetStorableType() == CREDIT_CARD_EXP_4_DIGIT_YEAR)) {
+ FillExpirationYearInput(value, type.GetStorableType(), field_data);
+ return true;
}
field_data->value = value;
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698