Zigbee ensure HTML encoding

This commit is contained in:
Stephan Hadinger 2021-02-14 19:30:28 +01:00
parent 8a849f83b6
commit cfb979aafd
2 changed files with 13 additions and 4 deletions

View File

@ -142,6 +142,15 @@ bool Z_Mapper::addEdge(const Z_Mapper_Edge & edge2) {
return true;
}
String EscapeHTMLString(const char *s_P) {
String s((const __FlashStringHelper*) s_P);
s.replace(F("&"), F("&"));
s.replace(F("\""), F("""));
s.replace(F("<"), F("&lt;"));
s.replace(F(">"), F("&gt;"));
return s;
}
void Z_Mapper::dumpInternals(void) const {
WSContentSend_P(PSTR("nodes:[" "{id:\"0x0000\",label:\"Coordinator\",group:\"o\",title:\"0x0000\"}"));
for (const auto & device : zigbee_devices.getDevices()) {
@ -150,7 +159,7 @@ void Z_Mapper::dumpInternals(void) const {
const char *fname = device.friendlyName;
if (fname != nullptr) {
WSContentSend_P(PSTR("%s"), fname);
WSContentSend_P(PSTR("%s"), EscapeJSONString(fname).c_str());
} else {
WSContentSend_P(PSTR("0x%04X"), device.shortaddr);
}

View File

@ -1960,9 +1960,9 @@ void ZigbeeShow(bool json)
WSContentSend_PD(msg[ZB_WEB_STATUS_LINE],
shortaddr,
device.modelId ? device.modelId : "",
device.manufacturerId ? device.manufacturerId : "",
name, sbatt, slqi);
device.modelId ? EscapeHTMLString(device.modelId).c_str() : "",
device.manufacturerId ? EscapeHTMLString(device.manufacturerId).c_str() : "",
EscapeHTMLString(name).c_str(), sbatt, slqi);
if(device.validLqi()) {
for(uint32_t j = 0; j < 4; ++j) {