Handle non-alphanumeric user ids #1
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In messenger chat, when a user's id has a character that would cause an html attribute to be invalid, anyone chatting with that user will not be able to see any messages. This occurs because the userid is used to create the id for an element that needs to be retrieved to add messages inside.
This is a pretty hacky fix, so do with it what you will. I'm replacing some non-alphanumeric characters that are actually valid in ids but simplicity's sake, I'm just replacing all of them. Here's the HTML 4 specification for what id attributes are allowed if you wanted to do it a bit better (HTML5 is slightly more permissive):
So yeah, simplicity wins.
Using this, there is potential that usernames could be duplicated (probably unlikely) or this code exploited. I would suggest not using the userid to create the id for the panel in the first place, and rather assign a auto generated id for the user when they connect to the chat, generating the id attribute based off that. That is, if assigning an id to this element is even necessary at all.