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

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

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: macros.h Created 5 years, 1 month 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
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/validation.h" 5 #include "components/autofill/core/browser/validation.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const char* const type = CreditCard::GetCreditCardType(number); 120 const char* const type = CreditCard::GetCreditCardType(number);
121 size_t required_length = 3; 121 size_t required_length = 3;
122 if (type == kAmericanExpressCard) 122 if (type == kAmericanExpressCard)
123 required_length = 4; 123 required_length = 4;
124 124
125 return code.length() == required_length; 125 return code.length() == required_length;
126 } 126 }
127 127
128 bool IsValidEmailAddress(const base::string16& text) { 128 bool IsValidEmailAddress(const base::string16& text) {
129 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) 129 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state)
130 const base::string16 kEmailPattern = base::ASCIIToUTF16( 130 const char kEmailPattern[] =
131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" 131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$";
132 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); 132 return MatchesPattern(base::UTF16ToASCII(text), kEmailPattern);
Ilya Sherman 2015/11/19 02:09:00 Please note: UTF16ToASCII is generally unsafe for
133 return MatchesPattern(text, kEmailPattern);
134 } 133 }
135 134
136 bool IsValidState(const base::string16& text) { 135 bool IsValidState(const base::string16& text) {
137 return !state_names::GetAbbreviationForName(text).empty() || 136 return !state_names::GetAbbreviationForName(text).empty() ||
138 !state_names::GetNameForAbbreviation(text).empty(); 137 !state_names::GetNameForAbbreviation(text).empty();
139 } 138 }
140 139
141 bool IsValidZip(const base::string16& text) { 140 bool IsValidZip(const base::string16& text) {
142 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); 141 const char kZipPattern[] = "^\\d{5}(-\\d{4})?$";
143 return MatchesPattern(text, kZipPattern); 142 return MatchesPattern(base::UTF16ToASCII(text), kZipPattern);
144 } 143 }
145 144
146 bool IsSSN(const base::string16& text) { 145 bool IsSSN(const base::string16& text) {
147 base::string16 number_string; 146 base::string16 number_string;
148 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); 147 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string);
149 148
150 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = 149 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S =
151 // serial number). The validation we do here is simply checking if the area, 150 // serial number). The validation we do here is simply checking if the area,
152 // group, and serial numbers are valid. 151 // group, and serial numbers are valid.
153 // 152 //
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 number_string.begin() + 9), 198 number_string.begin() + 9),
200 &serial) 199 &serial)
201 || serial == 0) { 200 || serial == 0) {
202 return false; 201 return false;
203 } 202 }
204 203
205 return true; 204 return true;
206 } 205 }
207 206
208 } // namespace autofill 207 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698