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

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: Merge two. 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
« no previous file with comments | « no previous file | chrome/browser/autofill/personal_data_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ac33ca24afbba7bb9a815588e4588c14bb80a17c..8430b15a49594eb1ee174cf069020b70f315837a 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"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
namespace {
@@ -69,6 +71,16 @@ 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.
+ const string16 kEmailPattern =
+ ASCIIToUTF16("^[^@]+@[^@]+\\.[a-z]{2,6}$");
+ WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern),
+ WebKit::WebTextCaseInsensitive);
+ return re.match(WebKit::WebString(StringToLowerASCII(value))) != -1;
+}
+
// Returns true if minimum requirements for import of a given |profile| have
// been met. An address submitted via a form must have at least these fields
// filled. No verification of validity of the contents is preformed. This is
@@ -231,6 +243,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;
« no previous file with comments | « no previous file | chrome/browser/autofill/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698