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

Decode causes lost data if there is no "__console_feed_remaining__0" entry #125

Open
lindapaiste opened this issue Jul 15, 2023 · 0 comments
Assignees

Comments

@lindapaiste
Copy link

lindapaiste commented Jul 15, 2023

We've had some problems over on the p5 Web Editor with upgrading from ^3.2.0 to ^3.5.0.

I've traced it back to the Decode function and the changes that were made there to support the limit option.

export function Decode(data: any): Message {
const decoded = replicator.decode(JSON.stringify(data))
// remove __console_feed_remaining__
decoded.data.pop()
return decoded
}

The problem is that sometimes the messages which we are decoding do not have a __console_feed_remaining__0 entry at the end of the data array. This could be due to improper usage on our end. But the Decode function will always remove the last element of the data array regardless of what the element actually is. The code would be safer if it validated the entry before removing it, using code similar to this:

if (typeof data === 'string' && data.includes(REMAINING_KEY)) {
name = REMAINING_KEY
data = data.split(REMAINING_KEY)[1]
}

@samdenty samdenty self-assigned this Aug 9, 2023
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

No branches or pull requests

2 participants