Trim whitespace when setting display names (#16031)
parent
7cbb2a00d1
commit
5eb3fd785b
|
@ -0,0 +1 @@
|
|||
Remove leading and trailing spaces when setting a display name.
|
|
@ -163,7 +163,7 @@ class ProfileHandler:
|
|||
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
|
||||
|
||||
|
|
|
@ -68,6 +68,18 @@ class ProfileTestCase(unittest.HomeserverTestCase):
|
|||
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",
|
||||
|
|
Loading…
Reference in New Issue