feature(cloudfunc) add decodeEntities

This commit is contained in:
coderaiser 2014-12-30 04:26:01 -05:00
parent ea949f0b81
commit e7822af805

View file

@ -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, '&lt;')
.replace(/>/g, '&gt;');
var Entities = {
'&nbsp;': ' ',
'&lt;': '<',
'&gt' : '>'
};
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
});