Merge pull request #890 from wycats/to-html-safe

Use toHTML vs. instanceof checks for SafeString
This commit is contained in:
Kevin Decker
2014-11-08 17:47:25 -06:00
3 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ function SafeString(string) {
this.string = string;
}
SafeString.prototype.toString = function() {
SafeString.prototype.toString = SafeString.prototype.toHTML = function() {
return "" + this.string;
};
+2 -2
View File
@@ -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) {
+6
View File
@@ -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(''), '');