documentcloud/underscore — Issue #389: "undefined" string throws error in template with custom syntax
Author: aglemann
Created: 2011-12-03 01:07:29+00:00
State: open

Using the custom syntax from the test in utility.js:

_.templateSettings = {
evaluate : /\{\{([\s\S]+?)\}\}/g,
interpolate : /\{\{=([\s\S]+?)\}\}/g
};

Any semblance of the property `undefined` or string "undefined" will throw the error:

"'undefined' is not a function (evaluating 'code.replace(/\\'/g, "'")')"

For example, the following test will fail:

var customUndefined = _.template("

{{ if (people != 'undefined') { }}
{{= people }}
{{ } }}

");
result = customUndefined({people : "Moe"});
equals(result, "

Moe

", 'can run arbitrary javascript in templates');