diff --git a/zerver/lib/users.py b/zerver/lib/users.py index cb24813fb1..2c22e945a7 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -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,9 +60,10 @@ 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: - raise JsonableError(_("Invalid characters in name!")) + 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 # users with ambiguous names, and likely have no real use, so we diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.py index 3e1a286c9f..ff40e3f0ea 100644 --- a/zerver/tests/test_settings.py +++ b/zerver/tests/test_settings.py @@ -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!")