Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Event server error when event data contains colons #177

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

gismya
Copy link
Contributor

@gismya gismya commented Nov 20, 2023

  • I have added automatic tests where applicable
  • The PR title is suitable as a release note
  • The PR contains a description of what has been changed
  • The description contains manual test instructions

Changes

The handleMessage methods split the message using the .split() method, which caused issues when the data contained groups of ::. This changes the message parsing to be more explicit.

Test

Test messages both with or without ::.

@gismya gismya requested a review from a team as a code owner November 20, 2023 12:06
@@ -204,7 +204,8 @@ export default class SimpleSocketIOClient {
* @private
*/
private handleMessage(event: MessageEvent): void {
const [packetType, data] = event.data.split(/:::?/);
const packetType = event.data[0]; // Get the first character of the message, the packet type
const data = event.data.replace(/^\d+:::?/, ""); // Remove the packet type and the : that split message parts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for + since packetType is always a single digit.

would be nice with a small comment that showcased the message format, explaining that double colons are when data is not set.

jimmycallin
jimmycallin previously approved these changes Nov 20, 2023
Copy link
Contributor

@jimmycallin jimmycallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, approved with additional suggestions

@gismya gismya merged commit be37f77 into main Nov 20, 2023
5 checks passed
@gismya gismya deleted the fix/event-server-crash-when-data-contains-colon branch November 20, 2023 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants