From 5a067d25772bb983827cc52657c26212592095c8 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 22 Oct 2025 23:59:46 +0200 Subject: [PATCH 1/3] Fix for UTF-8 problems with the ascii printer. Characters need to be in the ascii range, otherwise invalid UTF-8 data can (and is) written. So anything outside the 32-126 range is output as hexadecimal number. Signed-off-by: Hans Dijkema --- src/webui.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/webui.c b/src/webui.c index 79d48cd02..933cd6b2d 100644 --- a/src/webui.c +++ b/src/webui.c @@ -8848,10 +8848,16 @@ static void _webui_print_hex(const char* data, size_t len) { } static void _webui_print_ascii(const char* data, size_t len) { for (size_t i = 0; i < len; i++) { - if ((unsigned char)* data == 0x00) - _webui_log_debug("%c", 0xCF); - else - _webui_log_debug("%c", (unsigned char)* data); + if ((unsigned char)* data == 0x00) { + _webui_log_debug("0x%02X", 0xCF); + } else { + register unsigned char c = (unsigned char)* data; + if (c < 32 || c > 126) { + _webui_log_debug("0x%02X", c); + } else { + _webui_log_debug("%c", c); + } + } data++; } } From adf6ff88c56f44cc3ab091249b3307ee382d8ed2 Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:19:49 -0400 Subject: [PATCH 2/3] Updating code to follow current coding style --- src/webui.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/webui.c b/src/webui.c index 933cd6b2d..7d594a8ef 100644 --- a/src/webui.c +++ b/src/webui.c @@ -666,7 +666,7 @@ static bool _webui_check_certificate(const char* certificate_pem, const char* pr #endif #ifdef WEBUI_LOG static void _webui_print_hex(const char* data, size_t len); -static void _webui_print_ascii(const char* data, size_t len); +static void (const char* data, size_t len); static int _webui_http_log(const struct mg_connection* client, const char* message); #endif static WEBUI_THREAD_SERVER_START; @@ -8847,13 +8847,15 @@ static void _webui_print_hex(const char* data, size_t len) { } } static void _webui_print_ascii(const char* data, size_t len) { + // This function is used to print the protocol binary packets. the packet + // may have ASCII and `0x00` inside text, as well as other non-ascii bytes for (size_t i = 0; i < len; i++) { - if ((unsigned char)* data == 0x00) { - _webui_log_debug("0x%02X", 0xCF); + register unsigned char c = (unsigned char)* data; + if (c == 0x00) { + _webui_log_debug("%c", 0xCF); // Print `ยค` | TODO: Maybe we can simply print a blank space? } else { - register unsigned char c = (unsigned char)* data; if (c < 32 || c > 126) { - _webui_log_debug("0x%02X", c); + _webui_log_debug("[0x%02X]", c); } else { _webui_log_debug("%c", c); } From 1456940f30952be5cdae8a245c05ce2d791ff246 Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:21:06 -0400 Subject: [PATCH 3/3] Fix typo (_webui_print_ascii) --- src/webui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webui.c b/src/webui.c index 7d594a8ef..7a800aaf4 100644 --- a/src/webui.c +++ b/src/webui.c @@ -666,7 +666,7 @@ static bool _webui_check_certificate(const char* certificate_pem, const char* pr #endif #ifdef WEBUI_LOG static void _webui_print_hex(const char* data, size_t len); -static void (const char* data, size_t len); +static void _webui_print_ascii(const char* data, size_t len); static int _webui_http_log(const struct mg_connection* client, const char* message); #endif static WEBUI_THREAD_SERVER_START;