mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-10-27 06:21:26 +00:00
[JSON] Quick work-around for P126/P129 Still needs work string detection
This commit is contained in:
1 parent
775f69dcec
commit
513314996c
5 files changed
+13
-22
No files matched your search
@@ -377,10 +377,10 @@ boolean Plugin_126(uint8_t function, struct EventStruct *event, String& string)
|
||||
label += (P126_CONFIG_SHOW_OFFSET + (4 * varNr) + 1); // 4 = nr of bytes in an uint32_t.
|
||||
|
||||
if ((P126_CONFIG_SHOW_OFFSET + (4 * varNr) + 4) <= endCheck) { // Only show if still in range
|
||||
const String value = P126_formatValue(
|
||||
const String value = wrapWithQuotes(P126_formatValue(
|
||||
UserVar.getUint32(event->TaskIndex, varNr),
|
||||
event,
|
||||
true);
|
||||
true));
|
||||
|
||||
string += value;
|
||||
TaskValuesWriterHelper data(event);
|
||||
|
||||
@@ -470,10 +470,10 @@ boolean Plugin_129(uint8_t function, struct EventStruct *event, String& string)
|
||||
label += (P129_CONFIG_SHOW_OFFSET + (4 * varNr) + 1); // 4 = nr of bytes in an uint32_t.
|
||||
|
||||
if ((P129_CONFIG_SHOW_OFFSET + (4 * varNr) + 4) <= endCheck) { // Only show if still in range
|
||||
const String value = P129_formatValue(
|
||||
const String value = wrap_String(P129_formatValue(
|
||||
UserVar.getUint32(event->TaskIndex, varNr),
|
||||
event,
|
||||
true);
|
||||
true), '"');
|
||||
|
||||
string += value;
|
||||
TaskValuesWriterHelper data(event);
|
||||
|
||||
@@ -111,9 +111,7 @@ void KeyValueWriter_JSON::write(const KeyValueStruct& kv)
|
||||
|
||||
if (!kv._key.isEmpty()) {
|
||||
auto& pr = getPrint();
|
||||
pr.write('"');
|
||||
kv._key.print(pr);
|
||||
pr.write('"');
|
||||
pr.print(to_json_value(kv._key.toString(), true));
|
||||
pr.write(':');
|
||||
}
|
||||
|
||||
|
||||
@@ -545,6 +545,7 @@ String wrap_braces(const String& string) {
|
||||
}
|
||||
|
||||
String wrap_String(const String& string, char wrap) {
|
||||
if (stringWrappedWithChar(string, wrap)) return string;
|
||||
return wrap_String(string, wrap, wrap);
|
||||
}
|
||||
|
||||
@@ -594,7 +595,9 @@ String to_json_value(const String& value, bool wrapInQuotes) {
|
||||
return F("\"\"");
|
||||
}
|
||||
|
||||
if (is_json_formatted(value)) return value;
|
||||
if (is_json_formatted(value)) {
|
||||
if (!wrapInQuotes) return value;
|
||||
}
|
||||
|
||||
if (wrapInQuotes || mustConsiderAsJSONString(value)) {
|
||||
// Is not a numerical value, or BIN/HEX notation, thus wrap with quotes
|
||||
@@ -621,14 +624,14 @@ String to_json_value(const String& value, bool wrapInQuotes) {
|
||||
*/
|
||||
) {
|
||||
// Must replace characters, so make a deepcopy
|
||||
String tmpValue(value);
|
||||
String tmpValue = stripWrappingChar(value, '"');
|
||||
tmpValue.replace('\b', '^'); // \b Backspace (ascii code 08)
|
||||
tmpValue.replace('\t', ' '); // \t Tab
|
||||
tmpValue.replace('\n', '^'); // \n New line
|
||||
tmpValue.replace('\f', '^'); // \f Form feed (ascii code 0C)
|
||||
tmpValue.replace('\r', '^'); // \r Carriage return
|
||||
tmpValue.replace('\\', '^'); // Backslash
|
||||
tmpValue.replace('"', '\''); // Double quote
|
||||
tmpValue.replace(F("\""), F("\\\"")); // Double quote
|
||||
return wrap_String(tmpValue, '"');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,22 +618,12 @@ void handle_json_stream_task_value_data(TaskValuesWriterHelper*data)
|
||||
}
|
||||
|
||||
{
|
||||
String tmp = data->valName;
|
||||
|
||||
if (tmp.indexOf('"') != -1) {
|
||||
tmp.replace(F("\""), F("\\\""));
|
||||
}
|
||||
KeyValueStruct kv(F("Name"), tmp);
|
||||
KeyValueStruct kv(F("Name"), data->valName);
|
||||
kv.setID(data->valName_id);
|
||||
writer->write(kv);
|
||||
}
|
||||
{
|
||||
String tmp = data->value;
|
||||
|
||||
if (tmp.indexOf('"') != -1) {
|
||||
tmp.replace(F("\""), F("\\\""));
|
||||
}
|
||||
KeyValueStruct kv(F("Value"), tmp);
|
||||
KeyValueStruct kv(F("Value"), data->value);
|
||||
kv.setID(data->value_id);
|
||||
writer->write(kv);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user