GetStream / stream-chat-react-native

💬 React-Native Chat SDK ➜ Stream Chat. Includes a tutorial on building your own chat app experience using React-Native, React-Navigation and Stream
https://getstream.io/chat/sdk/react-native/
Other
975 stars 325 forks source link

[🐛] RegExp bug (user name) #2208

Closed mishkeTz closed 1 year ago

mishkeTz commented 1 year ago

Issue

The app breaks if the user name contains special characters.

Line that breaks the code:

useLatestMessagePreview.ts

const mentionedUsers = getMentionUsers(message.mentioned_users); const regEx = new RegExp(^(${mentionedUsers}));

example of message.mentioned_users that will break the RegExp

[{"banned": false, "created_at": "2023-04-25T09:19:40.933336Z", "id": "123123", "image": "https://some-url", "last_active": "2023-08-08T14:05:24.400094Z", "name": "Name :)", "online": false, "role": "user", "updated_at": "2023-08-07T20:31:58.690778Z"}]

Error catch: [SyntaxError: Invalid regular expression: unmatched parentheses]

The tagged user needs to be in the last message of the channel. (or maybe even not) When you open the channels list (when there's a channel rendered with that @mention last message) it will break the app and show a white screen.


Steps to reproduce

Steps to reproduce the behavior:

  1. Create a channel where there's a user with name i.e. "Name :)"
  2. Mention that user in the message

Expected behavior

The app doesn't break. [white screen]


Project Related Information


Additional context

  1. Either the application itself should not allow this kind of the name (we)
  2. Or you should kind of handle cases where the name can contain special characters
vishalnarkhede commented 1 year ago

We will check and get back to you :)

cc @khushal87

khushal87 commented 1 year ago

Umm, this will be easily reproducible since the name contains a special character ) that isn't escaped.

vishalnarkhede commented 1 year ago

Thanks for brining this up. I am able to reproduce this issue and we will fix it as soon as possible.