summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 20:22:00 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 20:22:00 +0000
commita2a1baf4c5f6b4246eff6b9ed9f480ec64539ee6 (patch)
treef709fb0e4d1d882d797b6c50b8c47f614dfceea0
parent69e2c17f4a5eabf97fe32b9f3afa51b32ce361ec (diff)
downloadchromium_src-a2a1baf4c5f6b4246eff6b9ed9f480ec64539ee6.zip
chromium_src-a2a1baf4c5f6b4246eff6b9ed9f480ec64539ee6.tar.gz
chromium_src-a2a1baf4c5f6b4246eff6b9ed9f480ec64539ee6.tar.bz2
Autofill should filter malformed emails addresses when form is submitted
BUG=71738 TEST=PersonalDataManagerTest.ImportFormDataBadEmail Review URL: http://codereview.chromium.org/6368067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73654 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc15
-rw-r--r--chrome/browser/autofill/personal_data_manager_unittest.cc44
2 files changed, 59 insertions, 0 deletions
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index ac33ca2..8430b15 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;
diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc
index 755c9f6..aee903e 100644
--- a/chrome/browser/autofill/personal_data_manager_unittest.cc
+++ b/chrome/browser/autofill/personal_data_manager_unittest.cc
@@ -555,6 +555,50 @@ TEST_F(PersonalDataManagerTest, ImportFormData) {
EXPECT_EQ(0, expected.Compare(*results[0]));
}
+TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) {
+ FormData form;
+ webkit_glue::FormField field;
+ autofill_test::CreateTestFormField(
+ "First name:", "first_name", "George", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Last name:", "last_name", "Washington", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Email:", "email", "bogus", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Address:", "address1", "21 Laussat St", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "City:", "city", "San Francisco", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "State:", "state", "California", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField(
+ "Zip:", "zip", "94102", "text", &field);
+ form.fields.push_back(field);
+ FormStructure form_structure(form);
+ std::vector<const FormStructure*> forms;
+ forms.push_back(&form_structure);
+ EXPECT_TRUE(personal_data_->ImportFormData(forms));
+
+ // Wait for the refresh.
+ EXPECT_CALL(personal_data_observer_,
+ OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
+
+ MessageLoop::current()->Run();
+
+ AutoFillProfile expected;
+ autofill_test::SetProfileInfo(&expected, NULL, "George", NULL,
+ "Washington", NULL, NULL, "21 Laussat St", NULL,
+ "San Francisco", "California", "94102", NULL, NULL, NULL);
+ const std::vector<AutoFillProfile*>& results = personal_data_->profiles();
+ ASSERT_EQ(1U, results.size());
+ EXPECT_EQ(0, expected.Compare(*results[0]));
+}
+
TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) {
FormData form;
webkit_glue::FormField field;