Fix a number of outstanding issues:
* {{}} escape their contents, {{{}}} and {{& }} do not
* Add support in the parser, tokenizer and AST for partials
with context (support is still not there in the runtime)
* Fix some inconsistencies with the old behavior involving
the correct printing of null and undefined
* Add Handlebars.Exception
* Fixed an issue involving ./foo and this/foo
* Fleshed out helperMissing in the specs (this will be
moved out into handlebars proper once registerHelper
and registerPartial are added)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
if(exports) {
|
||||
var Handlebars = {};
|
||||
}
|
||||
|
||||
Handlebars.Exception = function(message) {
|
||||
this.message = message;
|
||||
};
|
||||
|
||||
// Build out our basic SafeString type
|
||||
Handlebars.SafeString = function(string) {
|
||||
this.string = string;
|
||||
}
|
||||
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 = "";
|
||||
}
|
||||
|
||||
return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) {
|
||||
switch(str) {
|
||||
case "&":
|
||||
return "&";
|
||||
break;
|
||||
case '"':
|
||||
return "\"";
|
||||
case "\\":
|
||||
return "\\\\";
|
||||
break;
|
||||
case "<":
|
||||
return "<";
|
||||
break;
|
||||
case ">":
|
||||
return ">";
|
||||
break;
|
||||
default:
|
||||
return str;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if(exports) {
|
||||
exports.Utils = Handlebars.Utils;
|
||||
exports.SafeString = Handlebars.SafeString;
|
||||
exports.Exception = Handlebars.Exception;
|
||||
}
|
||||
Reference in New Issue
Block a user