Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Encoding/decode data sent over websocket to prevent issues with unicode data #32

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/mocksi-lite/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ function sendData(request: Map<string, any>) {
data.sessionID = sessionID;
}

webSocket?.send(btoa(JSON.stringify(data)));
// uri encode the data before sending to prevent
// problems with unicode data
const dataStr = JSON.stringify(data);
const encodedDataStr = encodeURIComponent(dataStr);
webSocket?.send(btoa(encodedDataStr));
});
}

Expand Down Expand Up @@ -262,7 +266,9 @@ webSocket.onmessage = (event) => {
}

if (command?.type === "RequestInterception") {
const interceptData = atob(command.payload);
// data will be uri encoded to prevent issues with unicode
const interceptDataEncoded = atob(command.payload);
const interceptData = decodeURIComponent(interceptDataEncoded);
const interception: RequestInterception = {
type: command.type,
url: command.url,
Expand Down
Loading