Fix #547 - _.templateSettings is unchanged by custom settings.

This commit is contained in:
Brad Dunbar
2012-04-09 22:49:12 -04:00
parent e80bbe6d03
commit d17834aeb0
2 changed files with 7 additions and 1 deletions

View File

@@ -186,4 +186,10 @@ $(document).ready(function() {
strictEqual(_.template(s)(data), 'x')
});
test('#547 - _.templateSettings is unchanged by custom settings.', function() {
ok(!_.templateSettings.variable);
_.template('', {}, {variable: 'x'});
ok(!_.templateSettings.variable);
});
});

View File

@@ -952,7 +952,7 @@
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
_.template = function(text, data, settings) {
settings = _.extend(_.templateSettings, settings);
settings = _.defaults(settings || {}, _.templateSettings);
// Compile the template source, taking care to escape characters that
// cannot be included in a string literal and then unescape them in code