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

Commit

Permalink
Trim whitespace when setting display names (#16031)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit-rathee authored Aug 1, 2023
1 parent 7cbb2a0 commit 5eb3fd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/16031.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove leading and trailing spaces when setting a display name.
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

0 comments on commit 5eb3fd7

Please sign in to comment.