Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Trim whitespace when setting display names #16031

Merged
merged 5 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def set_displayname(
400, "Displayname is too long (max %i)" % (MAX_DISPLAYNAME_LEN,)
)

displayname_to_set: Optional[str] = new_displayname
displayname_to_set: Optional[str] = new_displayname.strip()
if new_displayname == "":
displayname_to_set = None

Expand Down
12 changes: 12 additions & 0 deletions tests/rest/client/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ def test_set_displayname(self) -> None:
res = self._get_displayname()
self.assertEqual(res, "test")

def test_set_displayname_with_extra_spaces(self) -> None:
channel = self.make_request(
"PUT",
"/profile/%s/displayname" % (self.owner,),
content={"displayname": " test "},
access_token=self.owner_tok,
)
self.assertEqual(channel.code, 200, channel.result)

res = self._get_displayname()
self.assertEqual(res, "test")

def test_set_displayname_noauth(self) -> None:
channel = self.make_request(
"PUT",
Expand Down
Loading