mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 08:45:58 +03:00
[PR #5985] fix(common): parse JSON message body before emitting via Socket.IO #5448
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5448
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5985
Author: @mahmoodhamdi
Created: 3/13/2026
Status: 🔄 Open
Base:
main← Head:fix/socketio-json-message-parsing📝 Commits (2)
2563f2dfix(common): parse JSON message body before emitting via Socket.IO3b5f71cfix(common): restrict JSON parsing to objects/arrays and sync sent-event log📊 Changes
1 file changed (+16 additions, -2 deletions)
View changed files
📝
packages/hoppscotch-common/src/helpers/realtime/SIOConnection.ts(+16 -2)📄 Description
What does this PR do?
Fixes the Socket.IO client to parse JSON message bodies into actual objects before emitting them. Previously, JSON strings typed in the message body editor were emitted as-is, causing double-serialization on the wire.
Why?
I was testing a Socket.IO server and noticed the messages being sent had double-serialized JSON payloads. For example, sending
{"key": "value"}through the Socket.IO tab would produce:instead of the correct format:
This happens because
socket.emit()receives a string and serializes it again. Real socket.io clients (like the npm package) accept objects directly, soemit(event, {key: value})produces the correct wire format.Changes
SIOConnection.sendMessage(), the message body is now parsed viaJSON.parse()before being passed tosocket.emit()Testing
{"key": "value"}now correctly emits as a JSON objecthellostill works as a string[1, 2, 3]correctly emits as an array42correctly emits as a numberRelated Issues
Closes #4570
Summary by cubic
Parse JSON message bodies before emitting via Socket.IO so objects and arrays are sent as native values instead of double-serialized strings. Only parse payloads starting with { or [ to avoid coercing primitives, and log the actual emitted payload in the sent-event history; fall back to the raw string for invalid JSON.
Written for commit
3b5f71cd0a. Summary will update on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.