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

Unified Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 6368067: Autofill should filter malformed emails addresses when form is submitted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Created 9 years, 11 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
Index: chrome/browser/autofill/personal_data_manager.cc
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 52b4ca7dd233d3b19e47e6e1b443c57f2a4ddb2d..3082c333f64062cad4e0701e9bd08461c80ecec3 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -19,6 +19,8 @@
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression.h"
Ilya Sherman 2011/02/03 04:24:20 nit: 80-col? I'm not exactly sure what our style
dhollowa 2011/02/03 16:23:02 Nothing to be done. Can't be split.
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
namespace {
@@ -69,6 +71,18 @@ T* address_of(T& v) {
return &v;
}
+bool IsValidEmail(const string16& value) {
+ // This regex is more permissive than the official rfc2822 spec on the
+ // subject, but it does reject obvious non-email addresses.
Ilya Sherman 2011/02/03 04:24:20 nit: I find raw regexes hard to read; it would be
dhollowa 2011/02/03 16:23:02 I can't think of a comment that does any better th
+ const string16 kEmailPattern =
+ ASCIIToUTF16("^[^@]+@.+\\.[a-z]{2,4}$");
Ilya Sherman 2011/02/03 04:24:20 nit: Looks like ".museum" and ".travel" are valid
dhollowa 2011/02/03 16:23:02 Done.
+ WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern),
+ WebKit::WebTextCaseInsensitive);
+ bool match = re.match(
+ WebKit::WebString(StringToLowerASCII(value))) != -1;
Ilya Sherman 2011/02/03 04:24:20 nit: I would skip the local variable and just "ret
dhollowa 2011/02/03 16:23:02 Done.
+ return match;
+}
+
} // namespace
PersonalDataManager::~PersonalDataManager() {
@@ -220,6 +234,9 @@ bool PersonalDataManager::ImportFormData(
}
}
+ if (field_type.field_type() == EMAIL_ADDRESS && !IsValidEmail(value))
+ continue;
+
imported_profile_->SetInfo(AutoFillType(field_type.field_type()),
value);
++importable_fields;

Powered by Google App Engine
This is Rietveld 408576698