Skip to content

Commit 5fb5840

Browse files
fix regression on encoded html attributes
1 parent ddea2cd commit 5fb5840

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

home.html

+15-7
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@
3333
if (jsonMsg.Ports) {
3434
const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
3535
if (jsonMsg.Network) {
36-
printMsg = "<b>Network Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
36+
printMsg = "Network Ports:\n"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
3737
} else {
38-
printMsg = "<b>Serial Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
38+
printMsg = "Serial Ports:\n"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
3939
}
4040
} else if (Object.keys(jsonMsg).length !== 0) {
4141
printMsg = JSON.stringify(jsonMsg, undefined, 2);
4242
}
43+
44+
// when parsing JSON we're escaping some html charaters like "&:<>, we want to show their
45+
// original value in the log
46+
function decode(str) {
47+
let txt = new DOMParser().parseFromString(str, "text/html");
48+
return txt.documentElement.textContent;
49+
}
50+
printMsg = decode(printMsg);
51+
4352
messages.push(printMsg);
4453
if (messages.length > MESSAGES_MAX_COUNT) {
4554
messages.shift();
4655
}
47-
log.textContent = messages.join('<br><br>');
56+
log.textContent = messages.join('\n\n');
4857
if (autoscroll.checked) {
4958
log.scrollTop = log.scrollHeight - log.clientHeight;
5059
}
@@ -65,8 +74,7 @@
6574
$('#export').click(function() {
6675
var link = document.createElement('a');
6776
link.setAttribute('download', 'agent-log.txt');
68-
var text = log.innerHTML.replace(/<br>/g, '\n');
69-
text = text.replace(/<b>|<\/b>/g, '');
77+
var text = log.textContent;
7078
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
7179
link.click();
7280
});
@@ -83,13 +91,13 @@
8391
socket = io('http://{{$}}');
8492
}
8593
socket.on('disconnect', function(evt) {
86-
appendLog($('<div><b>Connection closed.</b></div>'))
94+
appendLog('Connection closed.')
8795
});
8896
socket.on('message', function(evt) {
8997
appendLog(evt);
9098
});
9199
} else {
92-
appendLog($('<div><b>Your browser does not support WebSockets.</b></div>'))
100+
appendLog('Your browser does not support WebSockets.')
93101
}
94102

95103
$("#input").focus();

0 commit comments

Comments
 (0)