Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

forms: Fix 500 error on realm creation with invalid email.

Anders Kaseorgc0287473b9dc
diff --git a/zerver/forms.py b/zerver/forms.py
index 36f46fada40..f97d16c47b5 100644
--- a/zerver/forms.py
+++ b/zerver/forms.py
@@ -239,7 +239,12 @@ def email_not_system_bot(email: str) -> None:
def email_is_not_disposable(email: str) -> None:
- if is_disposable_domain(Address(addr_spec=email).domain):
+ try:
+ domain = Address(addr_spec=email).domain
+ except ValueError:
+ raise ValidationError(_("Please use your real email address."))
+
+ if is_disposable_domain(domain):
raise ValidationError(_("Please use your real email address."))
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index 6e159385d5a..25cbf2013ba 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -3762,6 +3762,11 @@ class RealmCreationTest(ZulipTestCase):
# The remaining PreregistrationUser should have been used up:
self.assertEqual(PreregistrationUser.objects.filter(email=email, status=0).count(), 0)
+ @override_settings(OPEN_REALM_CREATION=True)
+ def test_invalid_email_signup(self) -> None:
+ result = self.client_post("/new/", {"email": "foo\x00bar"})
+ self.assert_in_response("Please use your real email address.", result)
+
@override_settings(OPEN_REALM_CREATION=True)
def test_mailinator_signup(self) -> None:
result = self.client_post("/new/", {"email": "[email protected]"})