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.

api: Fix encoding of strings in realm domain endpoint.

Gaurav Pandeyd4219da25468
diff --git a/static/js/settings_org.js b/static/js/settings_org.js
index b87d14f77f1..e7499232c84 100644
--- a/static/js/settings_org.js
+++ b/static/js/settings_org.js
@@ -1024,7 +1024,7 @@ export function build_page() {
const domain = widget.find(".new-realm-domain").val();
const allow_subdomains = widget.find(".new-realm-domain-allow-subdomains").prop("checked");
const data = {
- domain: JSON.stringify(domain),
+ domain,
allow_subdomains: JSON.stringify(allow_subdomains),
};
diff --git a/zerver/tests/test_realm_domains.py b/zerver/tests/test_realm_domains.py
index 59117a6f2c4..d135764fc2a 100644
--- a/zerver/tests/test_realm_domains.py
+++ b/zerver/tests/test_realm_domains.py
@@ -48,13 +48,13 @@ class RealmDomainTest(ZulipTestCase):
def test_create_realm_domain(self) -> None:
self.login("iago")
data = {
- "domain": orjson.dumps("").decode(),
+ "domain": "",
"allow_subdomains": orjson.dumps(True).decode(),
}
result = self.client_post("/json/realm/domains", info=data)
self.assert_json_error(result, "Invalid domain: Domain can't be empty.")
- data["domain"] = orjson.dumps("acme.com").decode()
+ data["domain"] = "acme.com"
result = self.client_post("/json/realm/domains", info=data)
self.assert_json_success(result)
realm = get_realm("zulip")
diff --git a/zerver/views/realm_domains.py b/zerver/views/realm_domains.py
index 8c8f2ee7865..1bc52c441d7 100644
--- a/zerver/views/realm_domains.py
+++ b/zerver/views/realm_domains.py
@@ -7,7 +7,7 @@ from zerver.lib.actions import do_add_realm_domain, do_change_realm_domain, do_r
from zerver.lib.domains import validate_domain
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_error, json_success
-from zerver.lib.validator import check_bool, check_string
+from zerver.lib.validator import check_bool
from zerver.models import RealmDomain, UserProfile, get_realm_domains
@@ -21,7 +21,7 @@ def list_realm_domains(request: HttpRequest, user_profile: UserProfile) -> HttpR
def create_realm_domain(
request: HttpRequest,
user_profile: UserProfile,
- domain: str = REQ(json_validator=check_string),
+ domain: str = REQ(),
allow_subdomains: bool = REQ(json_validator=check_bool),
) -> HttpResponse:
domain = domain.strip().lower()