Skip to content

Commit

Permalink
Merge pull request #515 from OpenEVSE/jeremypoulter/issue509
Browse files Browse the repository at this point in the history
Quick and dirty filter to ensure no >127 chars are sent over the websocket and hense valid UTF-8 is sent
  • Loading branch information
glynhudson authored Jan 25, 2023
2 parents 3c82b26 + 7ff34e4 commit 90627e5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,19 @@ void onWsConnect(MongooseHttpWebSocketConnection *connection)
web_server_event(doc);
}

/*
* Really simple 'conversion' of ASCII to UTF-8, basically only a few places send >127 chars
* so just filter those to be acceptable as UTF-8
*/
void web_server_send_ascii_utf8(const char *endpoint, const uint8_t *buffer, size_t size)
{
char temp[size];
for(int i = 0; i < size; i++) {
temp[i] = buffer[i] & 0x7f;
}
server.sendAll(endpoint, WEBSOCKET_OP_TEXT, temp, size);
}

void
web_server_setup() {
// SPIFFS.begin(); // mount the fs
Expand Down Expand Up @@ -1287,10 +1300,10 @@ web_server_setup() {
});

SerialEvse.onWrite([](const uint8_t *buffer, size_t size) {
server.sendAll("/evse/console", WEBSOCKET_OP_TEXT, buffer, size);
web_server_send_ascii_utf8("/evse/console", buffer, size);
});
SerialEvse.onRead([](const uint8_t *buffer, size_t size) {
server.sendAll("/evse/console", WEBSOCKET_OP_TEXT, buffer, size);
web_server_send_ascii_utf8("/evse/console", buffer, size);
});

server.on("/ws$")->
Expand Down

0 comments on commit 90627e5

Please sign in to comment.