diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index ad31f0c6..0302f42b 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -33,14 +33,33 @@ var Util; this.CHANNEL_TERMINAL_RESIZE= 'terminal-resize'; this.MAX_FILE_SIZE = 500 * 1024; - function encodeEntities(str) { - str = str - .replace(/\s/g, ' ') - .replace(//g, '>'); + var Entities = { + ' ': ' ', + '<': '<', + '>' : '>' + }; + + this.encodeEntities = function(str) { + Object.keys(Entities).forEach(function(code) { + var char = Entities[code], + reg = RegExp(char, 'g'); + + str = str.replace(reg, code); + }); return str; - } + }; + + this.decodeEntities = function(str) { + Object.keys(Entities).forEach(function(code) { + var char = Entities[code], + reg = RegExp(code, 'g'); + + str = str.replace(reg, char); + }); + + return str; + }; this.formatMsg = function(msg, name, status) { if (!status) @@ -231,7 +250,7 @@ var Util; linkResult = render(templateLink, { link : link, - name : encodeEntities(file.name), + name : CloudFunc.encodeEntities(file.name), attribute : attribute });