[Domoticz MQTT] Always wrap svalue with quotes

This commit is contained in:
Ton Huisman
2021-07-16 20:54:40 +02:00
parent 2c6a742205
commit 7ec426231d
3 changed files with 15 additions and 10 deletions
+8 -6
View File
@@ -383,20 +383,22 @@ String wrapIfContains(const String& value, char contains, char wrap) {
Format an object value pair for use in JSON.
\*********************************************************************************************/
String to_json_object_value(const __FlashStringHelper * object,
const __FlashStringHelper * value)
const __FlashStringHelper * value,
bool wrapInQuotes)
{
return to_json_object_value(String(object), String(value));
return to_json_object_value(String(object), String(value), wrapInQuotes);
}
String to_json_object_value(const __FlashStringHelper * object,
const String& value)
const String& value,
bool wrapInQuotes)
{
return to_json_object_value(String(object), value);
return to_json_object_value(String(object), value, wrapInQuotes);
}
String to_json_object_value(const String& object, const String& value) {
String to_json_object_value(const String& object, const String& value, bool wrapInQuotes) {
String result;
bool isBool = (Settings.JSONBoolWithoutQuotes() && ((value.equalsIgnoreCase(F("true")) || value.equalsIgnoreCase(F("false")))));
@@ -409,7 +411,7 @@ String to_json_object_value(const String& object, const String& value) {
result += F("\"\"");
return result;
}
if (!isBool && mustConsiderAsString(value)) {
if (wrapInQuotes || (!isBool && mustConsiderAsString(value))) {
// Is not a numerical value, or BIN/HEX notation, thus wrap with quotes
if ((value.indexOf('\n') != -1) || (value.indexOf('\r') != -1) || (value.indexOf('"') != -1)) {
// Must replace characters, so make a deepcopy
+6 -3
View File
@@ -126,13 +126,16 @@ String wrapIfContains(const String& value,
Format an object value pair for use in JSON.
\*********************************************************************************************/
String to_json_object_value(const __FlashStringHelper * object,
const __FlashStringHelper * value);
const __FlashStringHelper * value,
bool wrapInQuotes = false);
String to_json_object_value(const __FlashStringHelper * object,
const String& value);
const String& value,
bool wrapInQuotes = false);
String to_json_object_value(const String& object,
const String& value);
const String& value,
bool wrapInQuotes = false);
/*********************************************************************************************\
Strip wrapping chars (e.g. quotes)
+1 -1
View File
@@ -303,7 +303,7 @@ String serializeDomoticzJson(struct EventStruct *event)
json += ',';
json += to_json_object_value(F("nvalue"), F("0"));
json += ',';
json += to_json_object_value(F("svalue"), formatDomoticzSensorType(event));
json += to_json_object_value(F("svalue"), formatDomoticzSensorType(event), true);
break;
}
json += '}';