summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/safe-string.js2
-rw-r--r--lib/handlebars/utils.js4
-rw-r--r--spec/utils.js6
3 files changed, 9 insertions, 3 deletions
diff --git a/lib/handlebars/safe-string.js b/lib/handlebars/safe-string.js
index 2ae49aa..a6b8ecf 100644
--- a/lib/handlebars/safe-string.js
+++ b/lib/handlebars/safe-string.js
@@ -3,7 +3,7 @@ function SafeString(string) {
this.string = string;
}
-SafeString.prototype.toString = function() {
+SafeString.prototype.toString = SafeString.prototype.toHTML = function() {
return "" + this.string;
};
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js
index f38b7af..ce85077 100644
--- a/lib/handlebars/utils.js
+++ b/lib/handlebars/utils.js
@@ -53,8 +53,8 @@ export var isArray = Array.isArray || function(value) {
export function escapeExpression(string) {
// don't escape SafeStrings, since they're already safe
- if (string instanceof SafeString) {
- return string.toString();
+ if (string && string.toHTML) {
+ return string.toHTML();
} else if (string == null) {
return "";
} else if (!string) {
diff --git a/spec/utils.js b/spec/utils.js
index 0216c8d..4582e24 100644
--- a/spec/utils.js
+++ b/spec/utils.js
@@ -25,6 +25,12 @@ describe('utils', function() {
var string = new Handlebars.SafeString('foo<&"\'>');
equals(Handlebars.Utils.escapeExpression(string), 'foo<&"\'>');
+ var obj = {
+ toHTML: function() {
+ return 'foo<&"\'>';
+ }
+ };
+ equals(Handlebars.Utils.escapeExpression(obj), 'foo<&"\'>');
});
it('should handle falsy', function() {
equals(Handlebars.Utils.escapeExpression(''), '');