Skip to content

fix: prevent double serialization of websocket text messages (#6173)#6182

Merged
sid-bruno merged 1 commit intousebruno:fix/websocket-serialization-6173from
Praveenkumar02023:fix/websocket-text-quotes
Dec 22, 2025
Merged

fix: prevent double serialization of websocket text messages (#6173)#6182
sid-bruno merged 1 commit intousebruno:fix/websocket-serialization-6173from
Praveenkumar02023:fix/websocket-text-quotes

Conversation

@Praveenkumar02023
Copy link
Contributor

Description

Fixes #6173

This PR fixes a bug where WebSocket messages sent using the "TEXT" message type were being incorrectly serialized as JSON strings (e.g., sending "message" instead of message). This resulted in the server receiving payloads wrapped in unwanted double quotes.

Changes:

  • Modified packages/bruno-requests/src/ws/ws-client.js.
  • Updated the sendMessage function to conditionally stringify the payload.
  • Added a check: if messageToSend is already a string (TEXT mode), it is passed to the socket raw. If it is an object (JSON mode), it is stringified via JSON.stringify.

Verification:

  • Verified locally using a WebSocket server.
  • Confirmed that messages sent in TEXT mode are received by the server as raw text without extra quotes.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
image image

@helloanoop
Copy link
Contributor

Thanks for the PR @Praveenkumar02023

Assigning this to @sid-bruno @anusree-bruno to get this reviewed and merged

@sid-bruno
Copy link
Collaborator

Hey @Praveenkumar02023,

Thanks for the fix! This is leftover code from when WS only supported JSON messages, and there are a few more changes we’d like to make so things are a bit more robust.

If you’re up for it, we’d like to pass the WS request’s selected body type down to sendMessage and use that to determine whether something needs to be sanitized as JSON and stringified, or just sent as a string. Otherwise, I can pick up the PR and make the changes.

@Praveenkumar02023
Copy link
Contributor Author

Hi Sid, Please feel free to make the changes.
I have a lot of things on my plate right now as my end sems are going on, I'll be available after few weeks.
Thanks

@sid-bruno
Copy link
Collaborator

Hi Sid, Please feel free to make the changes. I have a lot of things on my plate right now as my end sems are going on, I'll be available after few weeks. Thanks

Understood, cool, i'll take this up

@sid-bruno sid-bruno added the adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers label Dec 3, 2025
@Praveenkumar02023
Copy link
Contributor Author

hey sid ,
I'm available for work, is there any update regarding this PR?

@sid-bruno sid-bruno changed the base branch from main to fix/websocket-serialization-6173 December 22, 2025 09:26
@sid-bruno
Copy link
Collaborator

Hey @Praveenkumar02023,
we got a little busy with things for v3, will be picking this up now.

@sid-bruno sid-bruno merged commit a4892bf into usebruno:fix/websocket-serialization-6173 Dec 22, 2025
2 checks passed
@sid-bruno
Copy link
Collaborator

Merging to extend, the rest of the mods will be done on #6479 , you can subscribe for that

bijin-bruno pushed a commit that referenced this pull request Dec 23, 2025
…#6479)

* fix: prevent double serialization of websocket text messages. (#6182)

* fix: improve websocket message handling and serialization

- Added normalization for message format to prevent double encoding.
- Updated queueMessage and sendMessage methods to handle message format.
- Refactored code for better readability and maintainability.

fix: enhance message normalization in WebSocket client

---------

Co-authored-by: Praveen kumar <praveenkumar042023@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket “TEXT” messages are sent with extra quotes (serialized as "string" instead of string)

4 participants