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

View File

@ -125,6 +125,14 @@ class ChangeSettingsTest(ZulipTestCase):
def test_illegal_characters_in_name_changes(self) -> None: def test_illegal_characters_in_name_changes(self) -> None:
self.login("hamlet") 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 # Now try a name with invalid characters
json_result = self.client_patch("/json/settings", dict(full_name="Opheli*")) json_result = self.client_patch("/json/settings", dict(full_name="Opheli*"))
self.assert_json_error(json_result, "Invalid characters in name!") self.assert_json_error(json_result, "Invalid characters in name!")