Skip to content

Commit ba3283c

Browse files
Fix regression showing escaped charaters (#871)
1 parent ddea2cd commit ba3283c

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

home.html

+29-20
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
}
@@ -60,13 +69,13 @@
6069
return false;
6170
}
6271
socket.emit('command', input.val());
72+
input.val('');
6373
});
6474

6575
$('#export').click(function() {
6676
var link = document.createElement('a');
6777
link.setAttribute('download', 'agent-log.txt');
68-
var text = log.innerHTML.replace(/<br>/g, '\n');
69-
text = text.replace(/<b>|<\/b>/g, '');
78+
var text = log.textContent;
7079
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
7180
link.click();
7281
});
@@ -83,15 +92,15 @@
8392
socket = io('http://{{$}}');
8493
}
8594
socket.on('disconnect', function(evt) {
86-
appendLog($('<div><b>Connection closed.</b></div>'))
95+
appendLog('Connection closed.')
8796
});
8897
socket.on('message', function(evt) {
8998
appendLog(evt);
9099
});
91100
} else {
92-
appendLog($('<div><b>Your browser does not support WebSockets.</b></div>'))
101+
appendLog('Your browser does not support WebSockets.')
93102
}
94-
103+
95104
$("#input").focus();
96105
});
97106
</script>
@@ -101,7 +110,7 @@
101110
height: 100%;
102111
}
103112

104-
body {
113+
body {
105114
margin: 0px;
106115
padding: 0px;
107116
background: #F8F9F9;
@@ -111,7 +120,7 @@
111120

112121
#container {
113122
display: flex;
114-
flex-direction: column;
123+
flex-direction: column;
115124
height: 100vh;
116125
width: 100%;
117126
}
@@ -126,15 +135,15 @@
126135
overflow-y: auto;
127136
}
128137

129-
#footer {
130-
display: flex;
138+
#footer {
139+
display: flex;
131140
flex-wrap: wrap;
132141
align-items: flex-start;
133142
justify-content: space-between;
134-
margin: 0px 15px 0px;
143+
margin: 0px 15px 0px;
135144
}
136145

137-
#form {
146+
#form {
138147
display: flex;
139148
flex-grow: 1;
140149
margin-bottom: 15px;
@@ -145,8 +154,8 @@
145154
}
146155

147156
#secondary-controls div {
148-
display: inline-block;
149-
padding: 10px 15px;
157+
display: inline-block;
158+
padding: 10px 15px;
150159
}
151160

152161
#autoscroll,
@@ -169,7 +178,7 @@
169178
box-shadow: 0 4px #95a5a6;
170179
margin-bottom: 4px;
171180
color: #000;
172-
cursor: pointer;
181+
cursor: pointer;
173182
font-size: 14px;
174183
letter-spacing: 1.28px;
175184
line-height: normal;
@@ -181,20 +190,20 @@
181190
}
182191

183192
.button:hover {
184-
box-shadow: 0 2px #95a5a6;
193+
box-shadow: 0 2px #95a5a6;
185194
outline: none;
186195
transform: translateY(2px);
187196
}
188197

189198
.button:active {
190-
box-shadow: none;
199+
box-shadow: none;
191200
transform: translateY(4px);
192201
}
193202

194203
.textfield {
195204
background-color: #dae3e3;
196205
width: auto;
197-
height: auto;
206+
height: auto;
198207
padding: 10px 8px;
199208
margin-left: 8px;
200209
vertical-align: top;

0 commit comments

Comments
 (0)