Tested that safestrings don't get escaped.

This commit is contained in:
Alan Johnson
2010-08-08 18:01:42 -04:00
parent 792251f6c9
commit cd4d0453f2
2 changed files with 12 additions and 1 deletions
+5 -1
View File
@@ -10,7 +10,11 @@ Handlebars = {
},
escape: function(string) {
if (string === null) {
// don't escape SafeStrings, since they're already safe
if (string instanceof Handlebars.SafeString) {
return string.toString();
}
else if (string === null) {
string = "";
}
+7
View File
@@ -35,6 +35,13 @@ test("escaping", function() {
shouldCompileTo("{{&awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
"expressions with {{& handlebars aren't escaped");
});
test("functions returning safestrings shouldn't be escaped", function() {
var hash = {awesome: function() { return new Handlebars.SafeString("&\"\\<>"); }};
shouldCompileTo("{{awesome}}", hash, '&\"\\<>',
"functions returning safestrings aren't escaped");
});
test("functions", function() {