Skip to content

Commit

Permalink
Add escapeHTML filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Arseneault committed May 13, 2012
1 parent c2c151c commit 4dca257
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/dali.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,34 @@ var global = (typeof (window) === "object") ? window : this;
var json;
json = eval("(" + stream + ")");
return json;
}
},
"escapeHTML": function (stream, args) {
var escapeTags = {
'&': '&',
'<': '&#60;',
'>': '&#62;',
'"': '&#34;',
"'": '&#39;',
'`': '&#96;',
'!': '&#33;',
'@': '&#64;',
'$': '&#36;',
'%': '&#37;',
'(': '&#40;',
')': '&#41;',
'=': '&#61;',
'+': '&#43;',
'{': '&#123;',
'}': '&#125;',
'[': '&#91;',
']': '&#93;',
',': '&#44;'
},
replaceTag = function(tag) {
return escapeTags[tag] || tag;
};
return stream.replace(/[&<>]/g, replaceTag);
}
}
});

Expand Down Expand Up @@ -1299,4 +1326,3 @@ var global = (typeof (window) === "object") ? window : this;


}(global, this.jQuery));

0 comments on commit 4dca257

Please sign in to comment.