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

Side by Side Diff: components/autofill/core/browser/autofill_field.cc

Issue 1905143002: Autofill: Check for common angular js prefix when filling exp month. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/autofill_field.h" 5 #include "components/autofill/core/browser/autofill_field.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // |field|. Since |value| is well defined but the website's |field| option 192 // |field|. Since |value| is well defined but the website's |field| option
193 // values may not be, some heuristics are run to cover all observed cases. 193 // values may not be, some heuristics are run to cover all observed cases.
194 bool FillExpirationMonthSelectControl(const base::string16& value, 194 bool FillExpirationMonthSelectControl(const base::string16& value,
195 const std::string& app_locale, 195 const std::string& app_locale,
196 FormFieldData* field) { 196 FormFieldData* field) {
197 // |value| is defined to be between 1 and 12, inclusively. 197 // |value| is defined to be between 1 and 12, inclusively.
198 int month = 0; 198 int month = 0;
199 if (!StringToInt(value, &month) || month <= 0 || month > 12) 199 if (!StringToInt(value, &month) || month <= 0 || month > 12)
200 return false; 200 return false;
201 201
202 // We trim the whitespace from the select values before attempting to convert 202 // We trim the whitespace and a specific prefix used in AngularJS from the
203 // them to months. 203 // select values before attempting to convert them to months.
204 std::vector<base::string16> trimmed_values(field->option_values.size()); 204 std::vector<base::string16> trimmed_values(field->option_values.size());
205 for (size_t i = 0; i < field->option_values.size(); ++i) 205 const base::string16 kNumberPrefix = ASCIIToUTF16("number:");
206 for (size_t i = 0; i < field->option_values.size(); ++i) {
207 base::ReplaceSubstringsAfterOffset(&trimmed_values[i], 0, kNumberPrefix,
Justin Donnelly 2016/04/21 20:11:10 ReplaceFirstSubstringAfterOffset?
Mathieu 2016/04/22 02:30:37 Oops, thanks!
208 ASCIIToUTF16(""));
206 base::TrimWhitespace(field->option_values[i], base::TRIM_ALL, 209 base::TrimWhitespace(field->option_values[i], base::TRIM_ALL,
207 &trimmed_values[i]); 210 &trimmed_values[i]);
211 }
208 212
209 if (trimmed_values.size() == 12) { 213 if (trimmed_values.size() == 12) {
210 // The select presumable only contains the year's months. 214 // The select presumable only contains the year's months.
211 // If the first value of the select is 0, decrement the value of |month| so 215 // If the first value of the select is 0, decrement the value of |month| so
212 // January is associated with 0 instead of 1. 216 // January is associated with 0 instead of 1.
213 int first_value; 217 int first_value;
214 if (StringToInt(trimmed_values[0], &first_value) && first_value == 0) 218 if (StringToInt(trimmed_values[0], &first_value) && first_value == 0)
215 --month; 219 --month;
216 } else if (trimmed_values.size() == 13) { 220 } else if (trimmed_values.size() == 13) {
217 // The select presumably uses the first value as a placeholder. 221 // The select presumably uses the first value as a placeholder.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 373 }
370 374
371 return false; 375 return false;
372 } 376 }
373 377
374 // Fills in the month control |field| with |value|. |value| should be a date 378 // Fills in the month control |field| with |value|. |value| should be a date
375 // formatted as MM/YYYY. If it isn't, filling will fail. 379 // formatted as MM/YYYY. If it isn't, filling will fail.
376 bool FillMonthControl(const base::string16& value, FormFieldData* field) { 380 bool FillMonthControl(const base::string16& value, FormFieldData* field) {
377 // Autofill formats a combined date as month/year. 381 // Autofill formats a combined date as month/year.
378 std::vector<base::string16> pieces = base::SplitString( 382 std::vector<base::string16> pieces = base::SplitString(
379 value, base::ASCIIToUTF16("/"), 383 value, ASCIIToUTF16("/"), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
380 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
381 if (pieces.size() != 2) 384 if (pieces.size() != 2)
382 return false; 385 return false;
383 386
384 // HTML5 input="month" is formatted as year-month. 387 // HTML5 input="month" is formatted as year-month.
385 base::string16 month = pieces[0]; 388 base::string16 month = pieces[0];
386 base::string16 year = pieces[1]; 389 base::string16 year = pieces[1];
387 if ((month.size() != 1 && month.size() != 2) || year.size() != 4) 390 if ((month.size() != 1 && month.size() != 2) || year.size() != 4)
388 return false; 391 return false;
389 392
390 // HTML5 input="month" expects zero-padded months. 393 // HTML5 input="month" expects zero-padded months.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 673 }
671 return best_match; 674 return best_match;
672 } 675 }
673 676
674 bool AutofillField::IsCreditCardPrediction() const { 677 bool AutofillField::IsCreditCardPrediction() const {
675 return AutofillType(server_type_).group() == CREDIT_CARD || 678 return AutofillType(server_type_).group() == CREDIT_CARD ||
676 AutofillType(heuristic_type_).group() == CREDIT_CARD; 679 AutofillType(heuristic_type_).group() == CREDIT_CARD;
677 } 680 }
678 681
679 } // namespace autofill 682 } // namespace autofill
OLDNEW
« 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