From 90bb707430409b137c54c7b37dc9abae17386b83 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 4 May 2021 11:10:24 +0200 Subject: [PATCH] Fix rule Invalid JSON message --- tasmota/xdrv_10_rules.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index b2692f6b0..5e74a99eb 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -500,7 +500,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all // Step2: Search rule_name int pos; int rule_name_idx = 0; - if ((pos = rule_name.indexOf(F("["))) > 0) { // "SUBTYPE1#CURRENT[1]" + if ((pos = rule_name.indexOf(F("["))) > 0) { // "SUBTYPE1#CURRENT[1]" rule_name_idx = rule_name.substring(pos +1).toInt(); if ((rule_name_idx < 1) || (rule_name_idx > 6)) { // Allow indexes 1 to 6 rule_name_idx = 1; @@ -508,10 +508,11 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all rule_name = rule_name.substring(0, pos); // "SUBTYPE1#CURRENT" } - String buf = event; // copy the string into a new buffer that will be modified + String buf = event; // Copy the string into a new buffer that will be modified //AddLog_P(LOG_LEVEL_DEBUG, PSTR("RUL-RM2: RulesRuleMatch |%s|"), buf.c_str()); + buf.replace("\\"," "); // "Disable" any escaped control character JsonParser parser((char*)buf.c_str()); JsonParserObject obj = parser.getRootObject(); if (!obj) { @@ -521,7 +522,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all } String subtype; uint32_t i = 0; - while ((pos = rule_name.indexOf(F("#"))) > 0) { // "SUBTYPE1#SUBTYPE2#CURRENT" + while ((pos = rule_name.indexOf(F("#"))) > 0) { // "SUBTYPE1#SUBTYPE2#CURRENT" subtype = rule_name.substring(0, pos); obj = obj[subtype.c_str()].getObject(); if (!obj) { return false; } // not found