Skip to content

Commit

Permalink
server-name: Unescape server name in window menu item.
Browse files Browse the repository at this point in the history
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: zulip#554.
  • Loading branch information
akashnimare authored Sep 3, 2018
1 parent 73dc3db commit 50647e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/renderer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const ConfigUtil = require(__dirname + '/js/utils/config-util.js');
const DNDUtil = require(__dirname + '/js/utils/dnd-util.js');
const ReconnectUtil = require(__dirname + '/js/utils/reconnect-util.js');
const Logger = require(__dirname + '/js/utils/logger-util.js');
const CommonUtil = require(__dirname + '/js/utils/common-util.js');

const { feedbackHolder } = require(__dirname + '/js/feedback.js');

const logger = new Logger({
Expand Down Expand Up @@ -177,7 +179,7 @@ class ServerManagerView {
index,
tabIndex,
url: server.url,
name: server.alias,
name: CommonUtil.decodeString(server.alias),
isActive: () => {
return index === this.activeTabIndex;
},
Expand Down
25 changes: 25 additions & 0 deletions app/renderer/js/utils/common-util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

let instance = null;

class CommonUtil {
constructor() {
if (instance) {
return instance;
} else {
instance = this;
}
return instance;
}

// unescape already encoded/escaped strings
decodeString(string) {
const parser = new DOMParser();
const dom = parser.parseFromString(
'<!doctype html><body>' + string,
'text/html');
return dom.body.textContent;
}
}

module.exports = new CommonUtil();

0 comments on commit 50647e3

Please sign in to comment.