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,)
|
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 == "":
|
if new_displayname == "":
|
||||||
displayname_to_set = None
|
displayname_to_set = None
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,18 @@ class ProfileTestCase(unittest.HomeserverTestCase):
|
||||||
res = self._get_displayname()
|
res = self._get_displayname()
|
||||||
self.assertEqual(res, "test")
|
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:
|
def test_set_displayname_noauth(self) -> None:
|
||||||
channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
|
|
Loading…
Reference in New Issue