Skip to content

Commit 50647e3

Browse files
authored
server-name: Unescape server name in window menu item.
Escaping is necessary to avoid any security risk but we need to unescape those strings in order to show them in the frontend otherwise it will have ugly special characters. We already escape server name in the db and unesacoe it in the left-sidebar. This PR adds the decodeString function in order to unescape strings in the menu items. Fixes: #554.
1 parent 73dc3db commit 50647e3

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

app/renderer/js/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const ConfigUtil = require(__dirname + '/js/utils/config-util.js');
1414
const DNDUtil = require(__dirname + '/js/utils/dnd-util.js');
1515
const ReconnectUtil = require(__dirname + '/js/utils/reconnect-util.js');
1616
const Logger = require(__dirname + '/js/utils/logger-util.js');
17+
const CommonUtil = require(__dirname + '/js/utils/common-util.js');
18+
1719
const { feedbackHolder } = require(__dirname + '/js/feedback.js');
1820

1921
const logger = new Logger({
@@ -177,7 +179,7 @@ class ServerManagerView {
177179
index,
178180
tabIndex,
179181
url: server.url,
180-
name: server.alias,
182+
name: CommonUtil.decodeString(server.alias),
181183
isActive: () => {
182184
return index === this.activeTabIndex;
183185
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
let instance = null;
4+
5+
class CommonUtil {
6+
constructor() {
7+
if (instance) {
8+
return instance;
9+
} else {
10+
instance = this;
11+
}
12+
return instance;
13+
}
14+
15+
// unescape already encoded/escaped strings
16+
decodeString(string) {
17+
const parser = new DOMParser();
18+
const dom = parser.parseFromString(
19+
'<!doctype html><body>' + string,
20+
'text/html');
21+
return dom.body.textContent;
22+
}
23+
}
24+
25+
module.exports = new CommonUtil();

0 commit comments

Comments
 (0)