-
Notifications
You must be signed in to change notification settings - Fork 1
Encoding/decode data sent over websocket to prevent issues with unicode data #32
Conversation
WalkthroughWalkthroughThe recent changes in Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant Client
participant WebSocket
participant Server
Client->>WebSocket: sendData(request)
WebSocket->>Client: encodeURIComponent(data)
Client->>WebSocket: webSocket.send(btoa(encodedDataStr))
Server-->>WebSocket: MessageReceived(event)
WebSocket->>Client: decodeURIComponent(interceptDataEncoded)
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love one-liner fixes 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/mocksi-lite/background.ts (2 hunks)
Additional comments not posted (2)
apps/mocksi-lite/background.ts (2)
71-75
: URI encoding implemented correctly to handle Unicode data.Consider adding a comment explaining why both
encodeURIComponent
andbtoa
are used here, as it might not be immediately clear to other developers.
269-271
: Decoding process correctly implemented to handle Unicode data.Ensure that all data sent and received over WebSocket in other parts of the application also follows this new encoding/decoding pattern for consistency.
Verification successful
The WebSocket data handling in
apps/mocksi-lite/background.ts
appears to be consistent with the new encoding/decoding pattern. Thesend
method usesbtoa
for encoding, and theonmessage
event handler decodes the data usingatob
anddecodeURIComponent
.
send
method:webSocket?.send(btoa(encodedDataStr));
onmessage
event handler:const interceptDataEncoded = atob(command.payload); const interceptData = decodeURIComponent(interceptDataEncoded);
This ensures that the data is correctly interpreted upon receipt.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all WebSocket data handling follows the new encoding/decoding pattern. # Test: Search for WebSocket data handling. Expect: Consistent use of `encodeURIComponent` and `decodeURIComponent`. rg --type typescript $'webSocket.*send' 'apps/mocksi-lite' rg --type typescript $'webSocket.*onmessage' 'apps/mocksi-lite'Length of output: 190
Script:
#!/bin/bash # Description: Verify that all WebSocket data handling follows the new encoding/decoding pattern. # Test: Search for WebSocket data handling. Expect: Consistent use of `encodeURIComponent` and `decodeURIComponent`. rg --type ts 'webSocket.*send' 'apps/mocksi-lite' rg --type ts 'webSocket.*onmessage' 'apps/mocksi-lite'Length of output: 374
Summary by CodeRabbit