users: Allow zero-width-joiners in user names.

Partially fixes: #20128.
This commit is contained in:
Alex Vandiver 2024-09-03 16:45:48 +00:00 committed by Tim Abbott
parent 58bc98afb5
commit cec0942b4b
2 changed files with 13 additions and 3 deletions

View File

@ -23,6 +23,7 @@ from zerver.lib.exceptions import (
OrganizationAdministratorRequiredError,
OrganizationOwnerRequiredError,
)
from zerver.lib.string_validation import check_string_is_printable
from zerver.lib.timestamp import timestamp_to_datetime
from zerver.lib.timezone import canonicalize_timezone
from zerver.lib.types import ProfileDataElementUpdateDict, ProfileDataElementValue, RawUserDict
@ -59,8 +60,9 @@ def check_full_name(
raise JsonableError(_("Name too long!"))
if len(full_name) < UserProfile.MIN_NAME_LENGTH:
raise JsonableError(_("Name too short!"))
for character in full_name:
if unicodedata.category(character)[0] == "C" or character in UserProfile.NAME_INVALID_CHARS:
if check_string_is_printable(full_name) is not None or any(
character in full_name for character in UserProfile.NAME_INVALID_CHARS
):
raise JsonableError(_("Invalid characters in name!"))
# Names ending with e.g. `|15` could be ambiguous for
# sloppily-written parsers of our Markdown syntax for mentioning

View File

@ -125,6 +125,14 @@ class ChangeSettingsTest(ZulipTestCase):
def test_illegal_characters_in_name_changes(self) -> None:
self.login("hamlet")
# Make sure unicode works
json_result = self.client_patch("/json/settings", dict(full_name="BLÅHAJ"))
self.assert_json_success(json_result)
# Make sure zero-width-joiners work
json_result = self.client_patch("/json/settings", dict(full_name="BLÅHAJ 🏳️‍⚧️"))
self.assert_json_success(json_result)
# Now try a name with invalid characters
json_result = self.client_patch("/json/settings", dict(full_name="Opheli*"))
self.assert_json_error(json_result, "Invalid characters in name!")