From 0bb83947e329c3ab4dd5fe716d8fd12199874e23 Mon Sep 17 00:00:00 2001 From: Adrian Scillato Date: Sat, 9 Apr 2022 05:35:17 -0300 Subject: [PATCH] Added Support to non JSON for WebQueryResponse --- tasmota/xdrv_01_webserver.ino | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index b1f7a2973..444eaa43d 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -3164,15 +3164,22 @@ int WebQuery(char *buffer) // Return received data to the user - Adds 900+ bytes to the code const char* read = http.getString().c_str(); // File found at server - may need lot of ram or trigger out of memory! ResponseClear(); - char text[2] = { 0 }; - text[0] = '.'; Response_P(PSTR("{\"" D_CMND_WEBQUERY "\":")); + char text[2] = { 0 }; + text[0] = *read++; + bool assume_json = (text[0] == '{') || (text[0] == '['); + if (!assume_json) { ResponseAppend_P(PSTR("\"")); } while (text[0] != '\0') { - text[0] = *read++; if (text[0] > 31) { // Remove control characters like linefeed - if (ResponseAppend_P(text) == ResponseSize()) { break; }; + if (assume_json) { + if (ResponseAppend_P(text) == ResponseSize()) { break; }; + } else { + if (ResponseAppend_P(EscapeJSONString(text).c_str()) == ResponseSize()) { break; }; + } } + text[0] = *read++; } + if (!assume_json) { ResponseAppend_P(PSTR("\"")); } ResponseJsonEnd(); #ifdef USE_SCRIPT extern uint8_t tasm_cmd_activ;