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

We should probably trim() received displaynames rather than preserving trailing/leading whitespace (SYN-647) #1510

Closed
matrixbot opened this issue Mar 10, 2016 · 2 comments · Fixed by #16031
Labels
A-Profiles Displaynames, avatars good first issue Good for newcomers O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.

Comments

@matrixbot
Copy link
Member

Submitted by @​matthew:matrix.org

(Imported from https://matrix.org/jira/browse/SYN-647)

@matrixbot matrixbot changed the title We should probably trim() received displaynames rather than preserving trailing/leading whitespace (SYN-647) We should probably trim() received displaynames rather than preserving trailing/leading whitespace (https://github.com/matrix-org/synapse/issues/1510) Nov 7, 2016
@matrixbot matrixbot changed the title We should probably trim() received displaynames rather than preserving trailing/leading whitespace (https://github.com/matrix-org/synapse/issues/1510) We should probably trim() received displaynames rather than preserving trailing/leading whitespace (SYN-647) Nov 7, 2016
@DMRobertson DMRobertson added good first issue Good for newcomers S-Minor Blocks non-critical functionality, workarounds exist. O-Uncommon Most users are unlikely to come across this or unexpected workflow A-Profiles Displaynames, avatars labels Apr 26, 2023
@DMRobertson
Copy link
Contributor

To do this:

  • replace displayname_to_set with displayname_to_set.strip() if it is not None
    displayname_to_set: Optional[str] = new_displayname
    if new_displayname == "":
    displayname_to_set = None
    # If the admin changes the display name of a user, the requesting user cannot send
    # the join event to update the displayname in the rooms.
    # This must be done by the target user himself.
    if by_admin:
    requester = create_requester(
    target_user,
    authenticated_entity=requester.authenticated_entity,
    )
    await self.store.set_profile_displayname(
    target_user.localpart, displayname_to_set
    )
  • add a test under in this suite
    class ProfileTestCase(unittest.HomeserverTestCase):
    which demonstrates that the new logic works.

@squahtx squahtx added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label May 3, 2023
@mohit-rathee
Copy link
Contributor

Well replacing displayname_to_set with displayname_to_set.strip() if it is not None may do something unintentional as if user send something like new_displayname=" " then code will save displayname_to_set="".
So let's directly trim new_displayname and then perform checks.

@clokep clokep linked a pull request Jul 31, 2023 that will close this issue
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Profiles Displaynames, avatars good first issue Good for newcomers O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants