From 072a7c7a3d4b38c45ced4da93aa0ffae447c44c5 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Tue, 11 Oct 2022 22:26:06 +0200 Subject: [PATCH] Fix #213: Check if topic ends with slash If this is not the case the subscription to the command topics will fail --- src/WebApi_mqtt.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/WebApi_mqtt.cpp b/src/WebApi_mqtt.cpp index 33db93c..78cbbd0 100644 --- a/src/WebApi_mqtt.cpp +++ b/src/WebApi_mqtt.cpp @@ -170,6 +170,13 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request) return; } + if (!root[F("mqtt_topic")].as().endsWith("/")) { + retMsg[F("message")] = F("Topic must end with slash (/)!"); + response->setLength(); + request->send(response); + return; + } + if (root[F("mqtt_port")].as() == 0 || root[F("mqtt_port")].as() > 65535) { retMsg[F("message")] = F("Port must be a number between 1 and 65535!"); response->setLength();