Escape HTML

This commit is contained in:
Eric Fredricksen
2010-07-19 12:42:21 -07:00
parent 8a9cae0abf
commit 92c8896a6f
4 changed files with 10 additions and 3 deletions
+7
View File
@@ -15,6 +15,11 @@ function tabulate(list) {
}
String.prototype.escapeHtml = function () {
return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
function template(tmpl, data) {
var brag = tmpl.replace(/\$([_A-Za-z.]+)/g, function (str, p1) {
var dict = data;
@@ -24,6 +29,8 @@ function template(tmpl, data) {
dict = tabulate(dict);
} else {
dict = dict[v.replace("_"," ")];
if (typeof dict == typeof "")
dict = dict.escapeHtml();
}
return null;
});