summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/utils.js
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-12-15 23:42:53 -0800
committerwycats <wycats@gmail.com>2010-12-15 23:42:53 -0800
commite15d675a64c7bf2c28fc52fb655705462ed60cbb (patch)
tree3ebf470cca34b042049d90f89b8792513ae95979 /lib/handlebars/utils.js
parentec948c7382603b88a6e80ab949120cca2b64fb5f (diff)
downloadhandlebars.js-e15d675a64c7bf2c28fc52fb655705462ed60cbb.zip
handlebars.js-e15d675a64c7bf2c28fc52fb655705462ed60cbb.tar.gz
handlebars.js-e15d675a64c7bf2c28fc52fb655705462ed60cbb.tar.bz2
Everything is working now on the new VM except for partials and inverse sections
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r--lib/handlebars/utils.js76
1 files changed, 38 insertions, 38 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js
index a600d6b..bc816d5 100644
--- a/lib/handlebars/utils.js
+++ b/lib/handlebars/utils.js
@@ -13,47 +13,47 @@ Handlebars.SafeString.prototype.toString = function() {
return this.string.toString();
};
-Handlebars.Utils = {
- escapeExpression: function(string) {
- // don't escape SafeStrings, since they're already safe
- if (string instanceof Handlebars.SafeString) {
- return string.toString();
- }
- else if (string === null) {
- string = "";
- }
+(function() {
+ var escape = {
+ "<": "&lt;",
+ ">": "&gt;",
+ };
+
+ var badChars = /&(?!\w+;)|[<>]/g;
+ var possible = /[&<>]/
+
+ var escapeChar = function(chr) {
+ return escape[chr] || "&amp;"
+ };
- return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) {
- switch(str) {
- case "&":
- return "&amp;";
- case '"':
- return "\"";
- case "\\":
- return "\\\\";
- case "<":
- return "&lt;";
- case ">":
- return "&gt;";
- default:
- return str;
+ Handlebars.Utils = {
+ escapeExpression: function(string) {
+ // don't escape SafeStrings, since they're already safe
+ if (string instanceof Handlebars.SafeString) {
+ return string.toString();
+ } else if (string === null) {
+ string = "";
+ }
+
+ if(!possible.test(string)) { return string; }
+ return string.replace(badChars, escapeChar);
+ },
+
+ isEmpty: function(value) {
+ if (typeof value === "undefined") {
+ return true;
+ } else if (value === null) {
+ return true;
+ } else if (value === false) {
+ return true;
+ } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
+ return true;
+ } else {
+ return false;
}
- });
- },
- isEmpty: function(value) {
- if (typeof value === "undefined") {
- return true;
- } else if (value === null) {
- return true;
- } else if (value === false) {
- return true;
- } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
- return true;
- } else {
- return false;
}
- }
-};
+ };
+})();
// END(BROWSER)
exports.Utils = Handlebars.Utils;